2015-12-15 38 views
2

在我的腳本中,當我打開一個消息框時,消息框始終在後臺打開,在所有其他應用程序和窗口後面運行。我試圖做兩件事(我很抱歉,如果它們應該是兩個問題,但我認爲是密切相關的)1.我希望消息框在所有應用程序需要呈現時顯示在前面,並且2.我希望將焦點更改爲消息框上的「okay」按鈕。在Powershell中,如何將消息框帶到前臺並將焦點更改爲消息框中的按鈕

首先我加載在MessageBox $hide = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

然後打開需要的時候。

do 
{ 
    $attempt = LogIn #recieves true (see line 233 comments) 
    $bad++ #attempt = true 


    if ($bad -lt $allock -and $attempt -eq $false) 
    { 
     Messagebox -Message "Wrong Password" -BoxTitle "Error" 
    } 

    if ($bad -eq $allock -and $attempt -eq $false) #false, skip 
    {  
     Messagebox -Message "Five Tries, You are almost Locked out, Try again" -BoxTitle "Error" 
    } 

    if ($bad -eq $lockout-and $attempt -eq $false) #false, skip 
    { 
     Messagebox -Message "Six tries, you are probably locked out. Good Luck." -BoxTitle "Lockout?" 
     break 
    } 
    #attempt = true  
} while ($attempt -ne $true) #true, exit 

雖然有關於如何在PowerShell中使用提示消息框的信息過多,我無法找到把箱子前面,將重點轉向輸入按鈕包裝盒上的任何信息。我會很感激任何指導或信息指針。謝謝。

+2

你能告訴我們'Messagebox'功能嗎?你需要爲'Show()'方法提供一個'MessageBoxDefaultButton',以便它專注於一個特定的按鈕 –

回答

1

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,系統模式,感嘆號,DefaultButton1」 工作,但它不是必需的。

「有是消息框樣式枚舉的一部分的各種其他組合

ApplicationModal,DefaultButton1,OkOnly,艾伯塔省,AbortRetryIgnore,YesNoCancel,YESNO,RetryCancel,嚴重,問題,感嘆號, 信息,DefaultButton2,DefaultButton3 ,SystemModal,MsgBoxHelp,MsgBoxSetForeground,MsgBoxRight,MsgBoxRtlReading「