MessageBoxDefaultButton Enum

Definitie

Hiermee geeft u constanten die de standaardknop op een MessageBox.

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

Velden

Name Waarde Description
Button1 0

De eerste knop in het berichtvak is de standaardknop.

Button2 256

De tweede knop in het berichtvak is de standaardknop.

Button3 512

De derde knop in het berichtvak is de standaardknop.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u een MessageBox met de opties kunt weergeven die worden ondersteund door deze overbelasting van Show. Nadat u hebt gecontroleerd of een tekenreeksvariabele leeg is, ServerNamewordt in het voorbeeld een MessageBox pictogram met een vraagvak weergegeven, zodat de gebruiker de optie heeft om de bewerking te annuleren. In het voorbeeld wordt het RightAlign lid van de MessageBoxOptions opsomming gebruikt om de tekst uit te lijnen op de rechterrand van het dialoogvenster. Als de retourwaarde van de Show methode wordt geƫvalueerd Yes, wordt het formulier dat wordt MessageBox weergegeven gesloten.

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

Opmerkingen

Deze opsomming wordt door de MessageBox klasse gebruikt.

Van toepassing op