Hi,
ich bin relativ neu in der Powershell Welt und komme an einer Gewissen Stelle nicht weiter.
Ich versuche etwas mit GUIs zu basteln. Jetzt ist mein Frage, ich habe ein Tastendruck Event und möchte damit eine Zahl oder ein Zeichen in eine Variable schreiben, sodass ich ihn außerhalb des Event aber noch verwenden kann.
Ich habe schon einiges getestet, aber komme leider nicht weiter.
#Fenster erstellen Add-Type -AssemblyName System.Windows.Forms $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = '500,300' $Form.text = "TestGUI" $Form.BackColor = "#ffffff" Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() #Strukturen des Fensters $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = New-Object System.Drawing.Point(400,400) $Form.text = "Form" $Form.TopMost = $false #Test1 Button $Test1 = New-Object system.Windows.Forms.Button $Test1.text = "1" $Test1.width = 200 $Test1.height = 200 $Test1.location = New-Object System.Drawing.Point(50,70) $Test1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) #Amazon Prime Button $Test2 = New-Object system.Windows.Forms.Button $Test2.text = "2" $Test2.width = 200 $Test2.height = 200 $Test2.location = New-Object System.Drawing.Point(300,70) $Test2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) #Disney+ Button $Test2 = New-Object system.Windows.Forms.Button $Test2.text = "3" $Test2.width = 200 $Test2.height = 200 $Test2.location = New-Object System.Drawing.Point(550,70) $Test2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10) $Form.controls.AddRange(@($Test1)) $Form.controls.AddRange(@($Test2)) $Form.controls.AddRange(@($Test2)) #Event nach Tastendruck $Test1.Add_Click({ $auswahl = 1 }) $Test2.Add_Click({ $auswahl = 2 }) $Test2.Add_Click({ Write-Host $script:auswahl Test3 }) [void]$Form.ShowDialog() if($auswahl -eq "Test1") { echo("if1")} else { echo("else3") }
Ich hoffe ihr könnt mir helfen.
Dankeschön im vorraus.
Grü0e