MessageBoxDefaultButton 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定定義 MessageBox上預設按鈕的常數。
public enum class MessageBoxDefaultButton
public enum MessageBoxDefaultButton
type MessageBoxDefaultButton =
Public Enum MessageBoxDefaultButton
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Button1 | 0 | 訊息框上的第一個按鈕是預設按鈕。 |
| Button2 | 256 | 訊息框上的第二個按鈕是預設按鈕。 |
| Button3 | 512 | 訊息框上的第三個按鈕是預設按鈕。 |
| Button4 | 768 | 規定訊息框上的說明按鈕應該是預設按鈕。 |
範例
以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示帶有問題框圖示的 a MessageBox ,讓使用者可以選擇取消該操作。 範例中使用 RightAlign 列舉的成員 MessageBoxOptions 將文字對齊到對話框的右側邊緣。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。
private:
void validateUserEntry2()
{
// Checks the value of the text.
if ( serverName->Text->Length == 0 )
{
// Initializes the variables to pass to the MessageBox::Show method.
String^ message = "You did not enter a server name. Cancel this operation?";
String^ caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons::YesNo;
System::Windows::Forms::DialogResult result;
// Displays the MessageBox.
result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
if ( result == ::DialogResult::Yes )
{
// Closes the parent form.
this->Close();
}
}
}
private void validateUserEntry2()
{
// Checks the value of the text.
if(serverName.Text.Length == 0)
{
// Initializes the variables to pass to the MessageBox.Show method.
string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(this, message, caption, buttons,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if(result == DialogResult.Yes)
{
// Closes the parent form.
this.Close();
}
}
}
Private Sub ValidateUserEntry2()
' Checks the value of the text.
If ServerName.Text.Length = 0 Then
' Initializes variables to pass to the MessageBox.Show method.
Dim Message As String = "You did not enter a server name. Cancel this operation?"
Dim Caption As String = "No Server Name Specified"
Dim Buttons As Integer = MessageBoxButtons.YesNo
Dim Result As DialogResult
'Displays a MessageBox using the Question icon and specifying the No button as the default.
Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
' Gets the result of the MessageBox display.
If Result = System.Windows.Forms.DialogResult.Yes Then
' Closes the parent form.
Me.Close()
End If
End If
End Sub
備註
此枚舉由類別使用 MessageBox 。