MessageBoxButton 列舉


指定訊息方塊中顯示的按鈕。 做為 Show 方法的引數。Used as an argument of the Show method.

public enum class MessageBoxButton
public enum MessageBoxButton
type MessageBoxButton = 
Public Enum MessageBoxButton


OK 0

訊息方塊會顯示 [確定] 按鈕。The message box displays an OK button.

OKCancel 1

訊息方塊會顯示 [確定] 和 [取消] 按鈕。The message box displays OK and Cancel buttons.

YesNo 4

訊息方塊會顯示 [是] 和 [否] 按鈕。The message box displays Yes and No buttons.

YesNoCancel 3

訊息方塊會顯示 [是]、[否] 和 [取消] 按鈕。The message box displays Yes, No, and Cancel buttons.


如需詳細資訊, 請參閱 GitHub 上的MessageBox 範例For more information, see the MessageBox Sample on GitHub.


根據預設, 此MessageBox.Show方法會顯示含有 [確定] 按鈕的訊息方塊。By default, the MessageBox.Show method displays a message box that has an OK button. MessageBox.Show您可以使用MessageBoxButton接受引數之方法的多載, 以指定不同的按鈕組合, 包括 [確定][確定] [ /取消]、 [ /否][是] /,/取消You can use overloads of the MessageBox.Show method that accept a MessageBoxButton argument in order to specify different combinations of buttons, which include OK, OK/Cancel, Yes/No, and Yes/No/Cancel.

使用者按一下按鈕的值是由MessageBox.Show傳回, 而則是MessageBoxResult列舉的其中一個值。The value of the button that a user clicks is returned by MessageBox.Show and is one of the values of the MessageBoxResult enumeration.

如果您指定YesNo, 則會停用訊息方塊標題列中的 [關閉] 按鈕。If you specify YesNo, you disable the Close button in the message box title bar. 不過, 所有其他選項都會啟用 [關閉] 按鈕。However, the Close button is enabled for all other options. 當使用者按一下 [關閉] 按鈕或按下ESC鍵時, 訊息方塊會傳回訊息方塊的MessageBoxResult.Cancel結果值。When a user clicks the Close button or presses the ESC key, a message box returns a message box result value of MessageBoxResult.Cancel. 不過, 如果訊息方塊只顯示 [確定] 按鈕, 按一下 [關閉] 按鈕或按ESC鍵, 會導致訊息方塊傳回的MessageBoxResult.OK訊息方塊結果值。However, if a message box displays only an OK button, clicking the Close button or pressing the ESC key causes a message box to return a message box result value of MessageBoxResult.OK.