Hier habe ich Euch ein Beispiel für eine Eingabebox. Das Ergebnis wird als Nachrichtenbox angezeigt.

 

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

# Allgemeines Windows Form vorbereiten
$Form               = New-Object System.Windows.Forms.Form
$Form.Text          = "Eingabebox"
$Form.StartPosition = "CenterScreen"
$Form.Size          = New-Object System.Drawing.Size(600,150)
$Form.MinimumSize   = New-Object System.Drawing.Size(600,150)
$Form.MaximumSize   = New-Object System.Drawing.Size(600,150)
$Form.SizeGripStyle = "hide"
$Form.Topmost       = $True

# Textbox
$TextBox          = New-Object System.Windows.Forms.TextBox 
$TextBox.Location = New-Object System.Drawing.Size(10,40) 
$TextBox.Size     = New-Object System.Drawing.Size(565,20) 


# Beschriftung
$Label          = New-Object System.Windows.Forms.Label
$Label.Location = New-Object System.Drawing.Size(10,20) 
$Label.Size     = New-Object System.Drawing.Size(565,20) 
$Label.Text     = "Hier könnt Ihr den Text eingeben."


# Schaltflächen
$ButtonOK          = New-Object System.Windows.Forms.Button
$ButtonOK.Location = New-Object System.Drawing.Size(425,80)
$ButtonOK.Size     = New-Object System.Drawing.Size(75,23)
$ButtonOK.Text     = "OK"
$ButtonOK.Add_Click({$Form.Close()})

$ButtonExit          = New-Object System.Windows.Forms.Button
$ButtonExit.Location = New-Object System.Drawing.Size(500,80)
$ButtonExit.Size     = New-Object System.Drawing.Size(75,23)
$ButtonExit.Text     = "Abbrechen"
$ButtonExit.Add_Click({$TextBox.Text="";$Form.Close()})


# Textbox Tastenerkennung
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter")  {$Form.Close()}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$TextBox.Text="";$Form.Close()}})

# Controls hinzufügen
$Form.Controls.Add($TextBox)
$Form.Controls.Add($Label)  
$Form.Controls.Add($ButtonOK)
$Form.Controls.Add($ButtonExit)

# Windowsfenster anzeigen
$Form.ShowDialog()

if ($TextBox.Text -ne "") {
    [System.Windows.Forms.MessageBox]::Show("Ergebnis = " + $TextBox.Text,"Eingabebox",[System.Windows.Forms.MessageBoxButtons]::OKCancel)
}

Kommentar schreiben

Kommentare: 0