1
我使用WinForms和PowerShell。在我的工具中,我想要一個複選框,當它被選中時,它會在旁邊顯示一條消息,而當未選中時,它將刪除該消息。使用Windows Forms和Powershell協助的CheckedChanged
我已經得到了這麼多(我相信有一個更好的方法來做到這一點)。這會使消息彈出,但當您取消選中該框時,消息不會消失。任何幫助,將不勝感激。謝謝!
$Checkbox_Errors.Add_CheckStateChanged({ ### Checkbox_Errors is the name of the checkbox
if ($Checkbox_Errors.Checked -eq $true)
{
$ErrorWarning1 = New-Object System.Windows.Forms.Label
$ErrorWarning1.Text = "WARNING: May take 3-5 Minutes" ### When checked, this is what it should display
$ErrorWarning1.ForeColor = "Red"
$ErrorWarning1.AutoSize = $True
$ErrorWarning1.Location = new-object System.Drawing.Point(170,13)
$groupbox.Controls.Add($ErrorWarning1)
}
})
$Checkbox_Errors.Add_CheckStateChanged({
if ($Checkbox_Errors.Unchecked -eq $true)
{
$ErrorWarning1 = New-Object System.Windows.Forms.Label
$ErrorWarning1.Text = "" ### I attempted this, where it would re-write
$ErrorWarning1.ForeColor = "Red"
$ErrorWarning1.AutoSize = $True
$ErrorWarning1.Location = new-object System.Drawing.Point(170,13)
$groupbox.Controls.Add($ErrorWarning1)
}
})
感謝您的回覆。這絕對是一種更優雅的處理方式。現在我只需要弄清楚我的「事件處理程序」是什麼。時間去學習。 – Jarom 2014-09-05 20:45:25
沒問題。這裏你的事件處理程序是'Add_CheckStateChanged'。只需用括號中的所有內容替換我答案中的最後一行代碼即可。它應該如下所示:'$ Checkbox_Errors.Add_CheckStateChanged({$ ErrorWarning1.Visible = $ Checkbox_Errors.Checked})'。 – 2014-09-05 20:50:25
我一直在試圖弄清楚這一整天!非常感謝!!! – Jarom 2014-09-05 20:54:48