我试图在我用 PS Forms 创建的消息框中显示一个计时器。我想要这样的东西:
1 秒后显示“您的电脑将在 10 秒后关闭”。
“您的电脑将在 9 秒后关闭”
“您的电脑将在 8 秒后关闭”等等。
希望你能帮我。
我没有看到刷新消息框中文本的方法。如果我必须这样做,我可能会弹出另一个带有标签的表单,并使用一个计时器在每个刻度上刷新标签的文本。
以下是使用潜在起点的代码示例:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Form = New-Object system.Windows.Forms.Form
$script:Label = New-Object System.Windows.Forms.Label
$script:Label.AutoSize = $true
$script:Form.Controls.Add($Label)
$Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 1000
$script:CountDown = 60
$Timer.add_Tick(
{
$script:Label.Text = "Your system will reboot in $CountDown seconds"
$script:CountDown--
}
)
$script:Timer.Start()
$script:Form.ShowDialog()
您将需要进行扩展以满足您的需求,例如条件逻辑以在倒计时达到 0 时执行您想要的任何操作(例如重新启动),也许添加一个用于中止的按钮等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)