Granatelbart
-
Gesamte Inhalte
2 -
Registriert seit
-
Letzter Besuch
Beiträge erstellt von Granatelbart
-
-
Guten Tag,
ich versuche aktuell ein dynamisches Menü aus einer TXT zu erstellen.
Das Menü baut sich soweit korrekt zusammen jedoch passen sich die Click-Button nicht an.
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') [void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') [void] [System.Windows.Forms.Application]::EnableVisualStyles() $WindowTitle = '*********' $Title = '********' $Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + "\powershell.exe") $Password = ******* $User = ****** $ComputerName = ******** $Command = "SSH Command" $secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd) $SessionID = New-SSHSession -ComputerName $ComputerName -Credential $Credentials -AcceptKey $Results = Invoke-SSHCommand -SessionId 0 -Command "****** list-instances | cut -f1 -d ':' --output-delimiter=' ' " echo $Results|select -ExpandProperty Output | Format-List | Out-File -FilePath c:\test\Process.txt # Main menu $MenuBox = New-Object System.Windows.Forms.Form $MenuBox.Size = New-Object System.Drawing.Size @(650,450) $MenuBox.Text = $WindowTitle $MenuBox.StartPosition = 'CenterScreen' $MenuBox.MaximizeBox = $False $MenuBox.AutoSize = $False $MenuBox.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D $MenuBox.Icon = $Icon $MenuBox.BackgroundImage = $Image $MenuBox.BackgroundImageLayout = 'None' # None, Tile, Center, Stretch, Zoom # Exit Button $ExitButton = New-Object System.Windows.Forms.Button $ExitButton.Location = New-Object System.Drawing.Size(540,370) $ExitButton.Size = New-Object System.Drawing.Size(75,23) $ExitButton.Text = 'Exit' $ExitButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",11,0,3,1) $ExitButton.Add_Click({ $MenuBox.Close() }) # Main menu Header Text $MenuHeader = New-Object System.Windows.Forms.Label $MenuHeader.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",14,1,3,1) $MenuHeader.Location = New-Object System.Drawing.Size(118,20) $MenuHeader.Size = New-Object System.Drawing.Size(380,40) $MenuHeader.Text = $Title $MenuHeader.BackColor = 'Transparent' $MenuHeader.TextAlign = [System.Drawing.ContentAlignment]::TopCenter $MenuBox.Controls.Add($MenuHeader) # Main menu $BoxLabel = New-Object System.Windows.Forms.Label $BoxLabel.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",10,0,3,1) $BoxLabel.Location = New-Object System.Drawing.Size(10,60) $BoxLabel.Size = New-Object System.Drawing.Size(680,20) $BoxLabel.Text = 'Select the category:' $BoxLabel.BackColor = 'Transparent' $MenuBox.Controls.Add($BoxLabel) # AD menu $ADBox = New-Object System.Windows.Forms.Form $ADBox.Size = New-Object System.Drawing.Size @(650,450) $ADBox.Text = $WindowTitle $ADBox.StartPosition = 'CenterParent' $ADBox.AutoSize = $False $ADBox.MaximizeBox = $False $ADBox.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D $ADBox.Icon = $Icon $ADBox.BackgroundImage = $Image # AD menu $Backup = New-Object System.Windows.Forms.Form $Backup.Size = New-Object System.Drawing.Size @(650,450) $Backup.Text = $WindowTitle $Backup.StartPosition = 'CenterParent' $Backup.AutoSize = $False $Backup.MaximizeBox = $False $Backup.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D $Backup.Icon = $Icon $Backup.BackgroundImage = $Image # install menu $install = New-Object System.Windows.Forms.Form $install.Size = New-Object System.Drawing.Size @(650,450) $install.Text = $WindowTitle $install.StartPosition = 'CenterParent' $install.AutoSize = $False $install.MaximizeBox = $False $install.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D $install.Icon = $Icon $install.BackgroundImage = $Image #######Restart Menü######### # Main menu button 1 # Main menu button 2 $Button2 = New-Object System.Windows.Forms.Button $Button2.Location = New-Object System.Drawing.Size(62,100) $Button2.Size = New-Object System.Drawing.Size(500,30) $Button2.Add_Click({ # Call Sub menu 1 $MenuBox.Close() $MenuBox.Dispose() $ADBox.Topmost = $True $ADBox.Add_Shown({$ADBox.Activate()}) [void] $ADBox.ShowDialog() }) $Button2.Text = 'Server Restart' $Button2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1) $MenuBox.Controls.Add($Button2) $MenuBox.Controls.Add($ExitButton) $form=New-Object System.Windows.Forms.Form function function-to-run{ $this.ForeColor=$this.Tag write-host $this.Tag -fore $this.Tag -back white } $arguments = get-content c:\test\Process.txt $i=0 foreach ($arg in $arguments){ $b=New-Object System.Windows.Forms.Button $b.Name=$arg $b.location="62,$(40*++$I)" $b.Size = New-Object System.Drawing.Size(500,30) $b.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",12,0,3,1) $b.Text="$arg" $b.Tag=$arg $b.Add_Click($Button_Click) $button_click = {write-host "hi $arg"} $form.controls.add($b) $ADBox.Controls.Add($b) $ADBox.Controls.Add($ExitButton1) } # Show Menu $MenuBox.Topmost = $True $MenuBox.Add_Shown({$MenuBox.Activate()}) [void] $MenuBox.ShowDialog()
Powershell GUI foreach menü
in Windows Forum — Scripting
Geschrieben · bearbeitet von Granatelbart
ja ich muss das Skript noch etwas aufräumen ist mir bewusst (mit unter weil ich am testen bin)
Diese genannten "Fehler" sind aber auch nicht mein derzeitiges Problem
Setze Strings immer in ' oder ". <<<< Das weiß ich wohl ist halt beim ersetzen durch * entfernt worden
Mein Problem liegt eher in diesem Bereich. Ich generiere immer nur das Gleiche Event für die unterschiedlichen Button