MessageBoxDefaultButton Enum

Definisi

Menentukan konstanta yang menentukan tombol default pada MessageBox.

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

Bidang

Button1 0

Tombol pertama pada kotak pesan adalah tombol default.

Button2 256

Tombol kedua pada kotak pesan adalah tombol default.

Button3 512

Tombol ketiga pada kotak pesan adalah tombol default.

Button4 768

Menentukan bahwa tombol Bantuan pada kotak pesan harus menjadi tombol default.

Contoh

Contoh kode berikut menunjukkan cara menampilkan dengan opsi yang MessageBox didukung oleh kelebihan beban ini.Show Setelah memverifikasi bahwa variabel string, ServerName, kosong, contoh menampilkan MessageBox dengan ikon kotak pertanyaan, menawarkan opsi kepada pengguna untuk membatalkan operasi. Contoh menggunakan RightAlign anggota MessageBoxOptions enumerasi untuk meratakan teks ke tepi kanan kotak dialog. Show Jika nilai pengembalian metode mengevaluasi ke Yes, formulir yang menampilkan MessageBox ditutup.

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

Keterangan

Enumerasi ini digunakan oleh MessageBox kelas .

Berlaku untuk