Windows 表格 (Powershell) |消息框出现两次
Windows Forms (Powershell) | Message Box showing up twice
希望你们一切都好!
下面的消息框出现了两次,我不知道为什么。
只有当我在按钮之间切换时才会发生这种情况。
你能帮我理解为什么吗?
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$VerUsersLabel,$VerUsersCancel,$VerUsersOK,$VerUsersTextBox,$FerLabelPanel))
$VerUsersOK.Add_Click({
if ($VerUsersTextBox.Textlength -eq 0){
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})
})
$AlButton.Add_Click({
$ActiveDirectory.controls.Clear()
$AlUsersOptionsGroupbox.controls.AddRange(@($AlUsersUnlockCheckBox,$AlUsersDisableCheckBox,$AlUsersMustChangeCheckBox,$AlUsersEnableCheckBox))
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$AlPasswordLabel,$AlPasswordTextBox,$AlUsersLabel,$AlUsersTextBox,$AlOKButton,$AlCancelButton,$AlCPasswordLabel,$AlCPasswordTextBox,$AlUsersOptionsGroupbox))
$AlOKButton.Add_Click({
if (($AlUsersTextBox.TextLength -eq 0) -or ($AlPasswordTextBox.TextLength -eq 0) -or ($AlCPasswordTextBox.TextLength -eq 0)){
$ButtonText = $AlButton.text
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})
})
[void]$ActiveDirectory.ShowDialog()
如前所述,您将 $AlOKButton.Add_Click
嵌套在 $AlButton.Add_Click
中。每次单击 $AlButton
时,您都会向 $AlOKButton
添加一个侦听器。如果您点击 $AlButton
10 次,消息框将显示 10 次。
$AlButton.Add_Click({
$ActiveDirectory.controls.Clear()
$AlUsersOptionsGroupbox.controls.AddRange(@($AlUsersUnlockCheckBox,$AlUsersDisableCheckBox,$AlUsersMustChangeCheckBox,$AlUsersEnableCheckBox))
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$AlPasswordLabel,$AlPasswordTextBox,$AlUsersLabel,$AlUsersTextBox,$AlOKButton,$AlCancelButton,$AlCPasswordLabel,$AlCPasswordTextBox,$AlUsersOptionsGroupbox))
})
$AlOKButton.Add_Click({
if (($AlUsersTextBox.TextLength -eq 0) -or ($AlPasswordTextBox.TextLength -eq 0) -or ($AlCPasswordTextBox.TextLength -eq 0)){
$ButtonText = $AlButton.text
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})
希望你们一切都好!
下面的消息框出现了两次,我不知道为什么。 只有当我在按钮之间切换时才会发生这种情况。
你能帮我理解为什么吗?
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$VerUsersLabel,$VerUsersCancel,$VerUsersOK,$VerUsersTextBox,$FerLabelPanel))
$VerUsersOK.Add_Click({
if ($VerUsersTextBox.Textlength -eq 0){
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})
})
$AlButton.Add_Click({
$ActiveDirectory.controls.Clear()
$AlUsersOptionsGroupbox.controls.AddRange(@($AlUsersUnlockCheckBox,$AlUsersDisableCheckBox,$AlUsersMustChangeCheckBox,$AlUsersEnableCheckBox))
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$AlPasswordLabel,$AlPasswordTextBox,$AlUsersLabel,$AlUsersTextBox,$AlOKButton,$AlCancelButton,$AlCPasswordLabel,$AlCPasswordTextBox,$AlUsersOptionsGroupbox))
$AlOKButton.Add_Click({
if (($AlUsersTextBox.TextLength -eq 0) -or ($AlPasswordTextBox.TextLength -eq 0) -or ($AlCPasswordTextBox.TextLength -eq 0)){
$ButtonText = $AlButton.text
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})
})
[void]$ActiveDirectory.ShowDialog()
如前所述,您将 $AlOKButton.Add_Click
嵌套在 $AlButton.Add_Click
中。每次单击 $AlButton
时,您都会向 $AlOKButton
添加一个侦听器。如果您点击 $AlButton
10 次,消息框将显示 10 次。
$AlButton.Add_Click({
$ActiveDirectory.controls.Clear()
$AlUsersOptionsGroupbox.controls.AddRange(@($AlUsersUnlockCheckBox,$AlUsersDisableCheckBox,$AlUsersMustChangeCheckBox,$AlUsersEnableCheckBox))
$ActiveDirectory.controls.AddRange(@($ToolsPanel,$ADToolsPanel,$AlPasswordLabel,$AlPasswordTextBox,$AlUsersLabel,$AlUsersTextBox,$AlOKButton,$AlCancelButton,$AlCPasswordLabel,$AlCPasswordTextBox,$AlUsersOptionsGroupbox))
})
$AlOKButton.Add_Click({
if (($AlUsersTextBox.TextLength -eq 0) -or ($AlPasswordTextBox.TextLength -eq 0) -or ($AlCPasswordTextBox.TextLength -eq 0)){
$ButtonText = $AlButton.text
[System.Windows.MessageBox]::Show('Não foi introduzida nenhuma informação',$ButtonText,'OK','Error')
}
})