WinForm - Add_KeyDown in TabPage



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 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 :


$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

$tabpage1 = New-object System.Windows.forms.TabPage
$tabpage1.Text = “User Information”

$tabpage2 = New-object System.Windows.forms.TabPage
$tabpage2.Text = “Test”

$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)
if($_.KeyCode -eq ‘Enter’)
$buttonOK.Text = “Ok”

[void] $windows2.ShowDialog()

Thank you for your help.


Someone can help me ?

Thank you.