[英]Do Something on WPF Form Minimize –PowerShell (version 5)
I have PowerShell script that creates a WPF form from inserted XML code. 我有从插入的XML代码创建WPF表单的PowerShell脚本。 This form will run on a kiosk station and has no window (so no maximize, minimize, or close buttons) and consumes the entire screen.
此表单将在自助服务站上运行,并且没有窗口(因此没有最大化,最小化或关闭按钮),并且会占用整个屏幕。
Even though the form itself has no window buttons, a person can still press the WIN key on a keyboard, get the task bar, right click on the form in the task bar and choose to minimize, maximize, or close for the form. 即使表单本身没有窗口按钮,一个人仍然可以按键盘上的WIN键,获取任务栏,右键单击任务栏中的表单并选择最小化,最大化或关闭表单。
So, I set an action for close to lock the workstation (which is better option for this kiosk instead of preventing the form from closing at all) by doing this: 因此,通过执行以下操作,我将关闭操作设置为锁定工作站(这是此信息亭的最佳选择,而不是完全阻止表单关闭):
$form.Add_Closing({
$shell = New-Object -ComObject "Wscript.Shell"
$shell.Run("%windir%\System32\rundll32.exe user32.dll,LockWorkStation")
})
I would also like to do this for Minimize if possible, but can't seem to figure out how. 如果可能的话,我也想针对“最小化”进行此操作,但似乎无法弄清楚该怎么做。
FYI. 仅供参考。 I'm not intending this to be a security feature per-se, but more so something that is better done then not for this kiosk station.
我本来不打算将其本身用作安全功能,但更重要的是,最好不要在此信息亭中进行某些操作。
if $form
is your form, then you could try this (wrapping the repetitive part in a function to stay DRY): 如果
$form
是您的表单,则可以尝试这样做(将函数中的重复部分包装为DRY):
function Lock-Workstation {
$shell = New-Object -ComObject "Wscript.Shell"
$shell.Run("%windir%\System32\rundll32.exe user32.dll,LockWorkStation")
}
$form.Add_Closing({ Lock-Workstation })
$form.Add_StateChanged({
if($form.WindowState -eq "Minimized") {
Lock-Workstation
}
})
Since you don't want the window to be resized anyway, you could simply use: 由于您无论如何都不希望调整窗口的大小,因此可以简单地使用:
$form.Add_StateChanged({ Lock-Workstation })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.