WinForm - Add_KeyDown in TabPage

Welcome Forums General PowerShell Q&A WinForm - Add_KeyDown in TabPage

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #177801

    Participant
    Topics: 2
    Replies: 4
    Points: 37
    Rank: Member

    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.

     

  • #177882

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

    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.

  • #177984

    Participant
    Topics: 2
    Replies: 4
    Points: 37
    Rank: Member

    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.

  • #178230

    Participant
    Topics: 2
    Replies: 4
    Points: 37
    Rank: Member

    Hello,

    Someone can help me ?

    Thank you.

You must be logged in to reply to this topic.