【发布时间】:2015-11-11 04:05:27
【问题描述】:
我正在使用 powershell 开发一个带有图形界面的小工具,我正在为这个问题发疯......
例如: 我在表单上有一个标签,显示 ping 的“实时”状态。 同时,如果您点击标签,则会显示一条弹出消息。
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 秒,点击标签是没有效果的。
请帮忙:(
【问题讨论】:
标签: powershell powershell-2.0 powershell-3.0