c# - Powershell 中的 MessageBox 未置于最前面

标签 c# .net powershell messagebox

我使用的应用程序允许我在网络中的设备上运行 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)

最佳答案

生成的窗口需要一个父窗口。如果他们不这样做,他们将落后于其他窗口(如您所见)。

以下内容与 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

关于c# - Powershell 中的 MessageBox 未置于最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41886745/

相关文章:

c# - 可以发送/不能读取.NET串口

c# - 如何使用项目按钮单击将 ListView 值传递到另一个页面?

c# - 动态加载引用其他 DLL 的 DLL

c# - 从未绑定(bind)列中的 DataGridViewComboBoxCell 获取选定索引和选定项

powershell - 使用 powershell 脚本递归列出广告组中的用户,无需使用 CmdLets

azure - 获取 KeyVault 通过 Powershell AZ CLI 获取访问策略

powershell - 在PowerShell中使用换行符连接数组

c# - 霍夫曼树:遍历

c# - System.Windows.Forms.DataVisualization 命名空间在一个类中很好,但在另一个类中却不行

.net - 使用 InstallUtil 卸载不存在的服务