鼠标事件在第一次计时器后不起作用 Tick [英] Mouse event don't work after first timer Tick
问题描述
我正在使用 powershell 开发一个带有图形界面的小工具,我对这个问题很着迷...
I'm using powershell to develop a little tool with graphic interface and I'm going crazy with this issue...
例如:我在表单上有一个标签,显示 ping 的实时"状态.同时,如果您单击标签,则会显示一条弹出消息.
For example: I have a label on a form that display "real-time" status of a ping. In the same time, if you click on the label, a popup message is displayed.
function GoogleStatus ($Label)
{
$Google = "www.google.com"
If (Test-Connection -ComputerName $Google -Count 1 -Quiet)
{Label.Text = "Yes"}
else
{Label.Text = "No"}
}
function HelloMsg
{
[System.Windows.Forms.MessageBox]::Show("Hello","Funny Window",0,32)
}
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#Forms
$Form = New-Object System.Windows.Forms.Form
$Form.Size = '150, 220'
$Label = New-Object System.Windows.Forms.Label
$Form.Controls.Add($Label)
$Label.Location = '10, 30'
$Label.Size = '75, 20'
$Label.Add_Click({HelloMsg})
#Timer Init
$Timer = New-Object 'System.Windows.Forms.Timer'
$Timer.Interval = 3000
Timer.Add_Tick({GoogleStatus $Label})
$Timer.Enabled = $True
#Show Interface
$Form.ShowDialog()
在计时器的前 3 秒内,单击标签正确显示弹出消息.但是如果我等了3秒以上,点击标签就没有效果了.
During the first 3 secondes of the timer, clicking on the label display correctly the popup message. But if I wait more than 3 seconds, clicking on the label has no effect.
请帮忙:(
推荐答案
测试连接的超时值必须小于您的计时器间隔.谢谢@Eric Walker https://stackoverflow.com/users/4270366/eric-walker
The timeout value for test-connection has to be less than your timer interval. Thank you @Eric Walker https://stackoverflow.com/users/4270366/eric-walker
这篇关于鼠标事件在第一次计时器后不起作用 Tick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!