第一次定时器勾选后鼠标事件不起作用

Mouse event don't work after first timer Tick

我正在使用 powershell 开发一个带有图形界面的小工具,我被这个问题弄疯了...

例如: 我在显示 "real-time" 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秒,点击标签就没有效果了。

请帮忙:(

我删除了代码中的 3 个拼写错误,它似乎有效(3 秒后我仍然看到弹出窗口):

function GoogleStatus ($Label) {
    $Google = "www.google.com"

    if(Test-Connection -ComputerName $Google -Count 1 -Quiet) {
        $Label.Text = "Yes" # missing $ sign here
    } else {
        $Label.Text = "No" # missing $ sign here
    }
}

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 }) # missing $ sign here
$Timer.Enabled = $True

#Show Interface
$Form.ShowDialog() 

测试连接的超时值必须小于您的计时器间隔。 谢谢@Eric Walker https://whosebug.com/users/4270366/eric-walker