WinForm - Add_KeyDown in TabPage

Dear,

 

I created a GUI with Winform/Powershell.

I have a tabcontrol with 3 tabpages

I have an issue when I want to add a KeyDown event on a tabpage (Enter to perform a click).

It works if I add the keydown event on my main form but not in a tabpage.

Thank you in advance for your answer.

 

is it possible to show us the code here. Showing us the code if possible will help us to understand the problem better.
You can use gist.github.com to share the code and paste the url here.

Yes sure.

You can find the test code that I made before implanting is my final project :

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

$windows2 = New-object System.Windows.Forms.Form
$windows2.size = New-object System.Drawing.size(1000,500)
$windows2.text = “Change Password”

$tabcontrol_userInformation = New-object System.Windows.Forms.TabControl
$tabcontrol_userInformation.Size = New-object System.Drawing.Size(965,440)
$tabcontrol_userInformation.Location = New-object System.Drawing.Size(10,10)
$tabcontrol_userInformation.Anchor = [System.Windows.Forms.AnchorStyles]::bottom -bor [System.Windows.Forms.AnchorStyles]::right -bor [System.Windows.Forms.AnchorStyles]::top -bor [System.Windows.Forms.AnchorStyles]::left
$windows2.Controls.Add($tabcontrol_userInformation)

$tabpage1 = New-object System.Windows.forms.TabPage
$tabpage1.Text = “User Information”
$tabcontrol_userInformation.Controls.Add($tabpage1)

$tabpage2 = New-object System.Windows.forms.TabPage
$tabpage2.Text = “Test”
$tabcontrol_userInformation.Controls.Add($tabpage2)

$buttonOK = New-object System.Windows.Forms.Button
$buttonOK.Location = New-object System.Drawing.Size(80,150)
$buttonOK.size = New-object System.Drawing.Size(80,30)
$buttonOK.Add_KeyDown({
if($_.KeyCode -eq ‘Enter’)
{
$buttonOK.PerformClick()
}
})
$buttonOK.Text = “Ok”
$buttonOK.Add_Click({$windows2.Close()})
$tabpage1.Controls.Add($buttonOK)

[void] $windows2.ShowDialog()

Thank you for your help.

Hello,

Someone can help me ?

Thank you.