我正在尝试在使用 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 时执行您想要的任何操作(例如重新启动),也许添加一个中止按钮等。
关于powershell - 如何在 Powershell 消息框中获取计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851482/