Home > OS >  System.Windows.Forms.TabPage - add_LostFocus and add_GotFocus not working?
System.Windows.Forms.TabPage - add_LostFocus and add_GotFocus not working?

Time:11-14

I have a form with multiple TabPages. I have buttons that I want to only be visible when one tab is in focus. Here's my code:

$form           = New-Object system.Windows.Forms.Form
$form.ClientSize    = New-Object System.Drawing.Point(350,380)
$form.text      = "Form"

$tabcontrol         = New-object System.Windows.Forms.TabControl
$tabcontrol.Size    = New-Object System.Drawing.Point(330,330)
$tabcontrol.Location    = New-Object System.Drawing.Point(10,10)
$form.Controls.Add($tabcontrol)

$tab0                         = New-object System.Windows.Forms.Tabpage
$tab0.DataBindings.DefaultDataSourceUpdateMode    = 0
$tab0.UseVisualStyleBackColor             = $True
$tab0.Text                    = "Tab0"
$tab0.AutoScroll                  = $true
$tabcontrol.Controls.Add($tab0)

$add_button           = New-Object System.Windows.Forms.Button
$add_button.Size      = New-Object System.Drawing.Size(23,23)
$add_button.Location  = New-Object System.Drawing.Point(10,350)
$add_button.Text      = " "
$form.Controls.Add($add_button)

$remove_button            = New-Object System.Windows.Forms.Button
$remove_button.Size       = New-Object System.Drawing.Size(23,23)
$remove_button.Location   = New-Object System.Drawing.Point(43,350)
$remove_button.Text       = "-"
$form.Controls.Add($remove_button)

$tab0.add_lostFocus({
    $add_button.Hide()
    $remove_button.Hide()
})
$tab0.add_gotFocus({
    $add_button.Show()
    $remove_button.Show()
})

$tab1                         = New-object System.Windows.Forms.Tabpage
$tab1.DataBindings.DefaultDataSourceUpdateMode    = 0
$tab1.UseVisualStyleBackColor             = $True
$tab1.Text                    = "Tab1"
$tabcontrol.Controls.Add($tab1)

Despite the add_GotFocus, and add_LostFocus on $tab0, when I change between tabs, the buttons stay visible.

What am I doing wrong and how can I accomplish this?

CodePudding user response:

I believe the events you're looking for are demo

  • Related