我有一个包含多个TabPage的窗体。我希望只有当一个选项卡成为焦点时按钮才可见。下面是我的代码:
$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)
尽管有add_GotFocus
和$tab0
上的add_LostFocus
,当我在选项卡之间切换时,按钮仍然可见。
我做错了什么?我该如何做到这一点?
1条答案
按热度按时间mnowg1ta1#
我相信您要查找的事件是Enter和Leave: