MessageBoxDefaultButton Wyliczenie

Definicja

Określa stałe definiujące przycisk domyślny na MessageBox.

public enum class MessageBoxDefaultButton
public enum MessageBoxDefaultButton
type MessageBoxDefaultButton = 
Public Enum MessageBoxDefaultButton
Dziedziczenie
MessageBoxDefaultButton

Pola

Button1 0

Pierwszy przycisk w oknie komunikatu jest przyciskiem domyślnym.

Button2 256

Drugi przycisk w oknie komunikatu jest przyciskiem domyślnym.

Button3 512

Trzeci przycisk w oknie komunikatu jest przyciskiem domyślnym.

Button4 768

Określa, że przycisk Pomoc w oknie komunikatu powinien być przyciskiem domyślnym.

Przykłady

W poniższym przykładzie kodu pokazano, jak wyświetlić element MessageBox z opcjami obsługiwanymi przez to przeciążenie elementu Show. Po sprawdzeniu, czy zmienna ciągu , jest pusta, ServerNamew przykładzie jest wyświetlana MessageBox ikona pola pytania, oferując użytkownikowi opcję anulowania operacji. W przykładzie RightAlignMessageBoxOptions użyto elementu członkowskiego wyliczenia, aby wyrównać tekst do prawej krawędzi okna dialogowego. Show Jeśli zwracana wartość metody zwróci wartość Yes, formularz, który wyświetla MessageBox wartość , jest zamknięty.

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

Uwagi

Ta wyliczenie jest używane przez klasę MessageBox .

Dotyczy