Hello,
I try to use the AcceptButton to close the window when the Enter Key is press but it not works.
[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$windows2 = New-object System.Windows.Forms.Form
$windows2.size = New-object System.Drawing.size(500,300)
$windows2.AcceptButton = $buttonOK2
$windows2.PreviewKey = $true
$windows2.text = "Test"
$buttonOK2 = New-object System.Windows.Forms.Button
$buttonOK2.Location = New-object System.Drawing.Size(60,55)
$buttonOK2.size = New-object System.Drawing.Size(80,25)
$buttonOK2.Add_Click({
$windows2.Close()})
$buttonOK2.Text = "Close"
$windows2.Controls.Add($buttonOK2)
$userID_Textbox = New-object System.Windows.Forms.TextBox
$userID_Textbox.Location = New-object System.Drawing.Size(55,15)
$userID_Textbox.size = New-Object System.Drawing.Size(100,20)
$userID_Textbox.Anchor = [System.Windows.Forms.AnchorStyles]::left -bor [System.Windows.Forms.AnchorStyles]::top
$userID_Textbox.AutoSize = $false
$windows2.controls.add($userID_Textbox)
$windows2.ShowDialog()
The Focus is automatically on the “Close” button but if I click on the textbox and press “Enter” nothing happen instead of close the window.
Someone can help me ?
Thank you.