MessageBoxDefaultButton Enumerazione

Definizione

Specifica le costanti che definiscono il pulsante predefinito in un MessageBox.

public enum class MessageBoxDefaultButton
public enum MessageBoxDefaultButton
type MessageBoxDefaultButton = 
Public Enum MessageBoxDefaultButton
Ereditarietà
MessageBoxDefaultButton

Campi

Nome Valore Descrizione
Button1 0

Il primo pulsante nella finestra di messaggio è il pulsante predefinito.

Button2 256

Il secondo pulsante nella finestra di messaggio è il pulsante predefinito.

Button3 512

Il terzo pulsante nella finestra di messaggio è il pulsante predefinito.

Button4 768

Specifica che il pulsante ? nella finestra di messaggio deve essere il pulsante predefinito.

Esempio

Nell'esempio di codice seguente viene illustrato come visualizzare un oggetto MessageBox con le opzioni supportate da questo overload di Show. Dopo aver verificato che una variabile stringa, ServerName, è vuota, nell'esempio viene visualizzato un MessageBox oggetto con un'icona della casella della domanda, offrendo all'utente l'opzione di annullare l'operazione. Nell'esempio viene utilizzato il RightAlign membro dell'enumerazione MessageBoxOptions per allineare il testo al bordo destro della finestra di dialogo. Se il Show valore restituito del metodo restituisce Yes, il modulo visualizzato viene MessageBox chiuso.

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

Commenti

Questa enumerazione viene utilizzata dalla MessageBox classe .

Si applica a