admin管理员组文章数量:1291002
I have a form with some questions on it and MaskedTextBoxes for user input. I have that validation for possible entries.
With the question/text boxes, the user can put something into the textbox, but can, of course, enter nothing and click the 'Next' button. This results in an error for which I display an error dialog box. This happens when the focus is lost on the textbox, which tells the user they must enter up to 5 characters, however, because I have this being trapped by a focuslost event, if the user just clicks the 'Cancel' button to exit, the focuslost event kicks in first and displays the error dialog box, rather than just exiting. I need to figure out a way to trap the button click before the focuslost.
Now I know this is not possible, so am really looking for a different way to allow the cancel button to be clicked without the focuslost event trapping it as an error.
The code for the focuslost is below. Of course it always runs this first, before getting to the 'Cancel' button click code block.
function tb1validation_focuslost {
$script:ans1 = $tb1.Text.tostring()
if ($ans1 -le 0 -xor $ans1 -gt 365){
$f2.controls.AddRange(@($e1,$ok2))
$f1.topmost = $False
$f2.Topmost = $True
$e1.text = "Error - Out of range here."
[void]$f2.ShowDialog()
$tb1.focus()
}
elseif ($ans1 -gt 0 -and $ans1 -le 365) {
# *** Turn on second question ***
$script:now = [datetime]::Today.AddDays(-$ans1)
$script:q1done = 1
$tb1.Enabled = $false
$q2.visible = $True
$tb2.visible = $True
$tb2.focus()
}
}
$tb1.add_leave({tb1validation_focuslost})
Not sure the code is going to help. I just need advice on how to allow a cancel button to be clicked and then the form closes without any error.
本文标签: powershellTrying to trap a button click before focuslost eventStack Overflow
版权声明:本文标题:powershell - Trying to trap a button click before focuslost event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741520258a2383138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论