Hi,
i have past my day to search a solution for my probleme, i have check all the Microsoft Doc and lot’s of google thing but nothing seems work (Maybe i’m just bad ).
My problem is, i want to create a form (system.window.form) who have 2 thing, a button and a textbox (ill post the code after) and when i tip something in the textbox and press ‘enter’ i want my event ‘click’ on the ‘Ok’ boutton…
I don’t want to use the form method acceptebutton i have succefully done what i want that way but i need to have a proper event handler.
the following code is just an example :
#Create the 3 thing, form, button, textbox
$FormResearch = New-Object system.Windows.Forms.Form
$btn_Research = New-Object system.Windows.Forms.Button
$TextBox_champResearch = New-Object system.Windows.Forms.TextBox
#Form setting
$FormResearch.ClientSize = ‘400,407’
$FormResearch.text = “FormTittle”
$FormResearch.TopMost = $false
$FormResearch.AcceptButton = $btn_Research
#Button setting
$btn_Research.text = “buttonTittle”
$btn_Research.width = 106
$btn_Research.height = 18
$btn_Research.location = New-Object System.Drawing.Point(4,344)
$btn_Research.Add_Click({
#If my event work that need to print that
write-host “ok”
})
#Textbox setting
$TextBox_champResearch.width = 283
$TextBox_champResearch.height = 20
$TextBox_champResearch.location = New-Object System.Drawing.Point(113,344)
$TextBox_champResearch.Font = ‘Microsoft Sans Serif,10’
$TextBox_champResearch.Add_KeyDown{{
if ($_.KeyChar -eq 13) #Si la touche entrée est “Enter” faire :
{
$btn_Research.PerformClick()
}
}}
$FormResearch.controls.AddRange(@($TextBox_champResearch,$btn_Research))
[void]$FormResearch.ShowDialog()
So i need something like that. At the start i have set the event handler on the form but it’s doesnt work, after i have set it in the Textbox but not better.
Hope u can solve my problem, the craziest thing is im sure that it work well fiew day ago…
PS : I’m not english sry for my poor language.
Cordally,
Xavier.