Powershell中的MessageBox没有带到前面

问题描述 投票:1回答:2

我正在使用一个应用程序,它允许我在我的网络中的设备上运行Powershell脚本,我需要使用MessageBox提示用户。

我的脚本创建了MessageBox,但我的问题是它总是显示在我的应用程序后面。我尝试了一个在线解决方案,建议创建一个属性Topmost = true的新表单,并将其作为第一个参数传递,但它似乎不起作用。有什么事情表明我做错了吗?

Add-Type -AssemblyName PresentationCore,PresentationFramework

$top = new-Object System.Windows.Forms.Form -property @{Topmost=$true}
$Result = [System.Windows.Forms.MessageBox]::Show($top, $MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
c# .net powershell messagebox
2个回答
3
投票

产生的窗户需要父母。如果他们不这样做,他们将落后于其他窗户(正如你所发现的那样)。

以下不是与PowerShell相关的......但是你需要知道/做什么才能到达你想去的地方......

Why isn't MessageBox TopMost?

可能

In Powershell how do I bring a messagebox to the foreground, and change focus to a button in the message box


2
投票

您不需要使用[System.Windows.Forms.Form]对象,可以使用$this变量作为第一个参数在1行中执行:

$Result = [System.Windows.Forms.MessageBox]::Show($this, $MessageBody, $MessageTitle, $ButtonType, $MessageIcon)
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.