Mouse event don't work after first timer Tick

▼魔方 西西 提交于 2019-12-02 13:40:30

I have removed 3 typos in the code, and it seems to work (I still get the popup after 3 seconds have elapsed) :

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() 
Nick32342

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!