在Powershell中,如何将消息框带到前台,并将焦点更改为消息框中的按钮

时间:2015-12-15 21:09:47

标签: powershell

在我的脚本中打开消息框时,消息框始终在后台打开,在所有其他应用程序和窗口运行后面。我正在尝试做两件事(如果他们应该是两个问题我道歉,但我认为这些问题密切相关)1。我希望消息框在所有应用程序的前面显示,当它需要礼物时,2.我想要将焦点更改为消息框上的“正常”按钮。

首先我加载消息框<body data-hijacking="off" data-animation="scaleDown"> <section class="cd-section visible"> <div> <h2 class="homepageheader">Beerbulance</h2> <p> text</p> </div> </section> cd-section { height: 100vh; } .cd-section h2 { line-height: 100vh; text-align: center; font-size: 2.4rem; } .cd-section h2.homepageheader{ font-size: 800%; } .cd-section:first-of-type > div { background-color: #09c003; } .cd-section:first-of-type > div::before { /* alert -> all scrolling effects are not visible on small devices */ content: 'Effects not visible on mobile!'; position: absolute; width: 100%; text-align: center; top: 20px; z-index: 2; font-weight: bold; font-size: 1.3rem; text-transform: uppercase; color: #09c003;

然后在需要时打开。

$hide = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

虽然有很多关于如何在powershell中使用消息框的信息,但我无法找到有关将盒子放到前面的任何信息,并将焦点更改为方框上的输入按钮。我将不胜感激任何指导或指向信息。谢谢。

1 个答案:

答案 0 :(得分:2)

来自http://blogs.msdn.com/b/sonam_rastogi_blogs/archive/2015/09/01/keeping-powershell-visualbasic-messagebox-in-focus.aspx

[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") 
[Microsoft.VisualBasic.Interaction]::MsgBox("Processing Completed.", "YesNoCancel,SystemModal,Information,DefaultButton2", "Success")
[Microsoft.VisualBasic.Interaction]::MsgBox("Five Tries, You are almost Locked out, Try again", "OKOnly,SystemModal,Exclamation", "Lockout?")

最后一个示例也适用于“OKOnly,SystemModal,感叹号, DefaultButton1 ”,但不是必需的。

“Message Box Style Enumerator中有各种其他组合

ApplicationModal,DefaultButton1,OkOnly,OkCancel,AbortRetryIgnore,YesNoCancel,YesNo,RetryCancel,Critical,Question,Exclamation, 信息,DefaultButton2,DefaultButton3,SystemModal,MsgBoxHelp,MsgBoxSetForeground,MsgBoxRight,MsgBoxRtlReading“