DialogResult 列舉

定義

指定識別項以指示對話方塊的傳回值。Specifies identifiers to indicate the return value of a dialog box.

public enum class DialogResult
[System.Runtime.InteropServices.ComVisible(true)]
public enum DialogResult
type DialogResult = 
Public Enum DialogResult
繼承
DialogResult
屬性

欄位

Abort 3

對話方塊傳回值是 Abort (通常由標記為 [中止] 的按鈕傳回)。The dialog box return value is Abort (usually sent from a button labeled Abort).

Cancel 2

對話方塊傳回值是 Cancel (通常由標記為 [取消] 的按鈕傳回)。The dialog box return value is Cancel (usually sent from a button labeled Cancel).

Ignore 5

對話方塊傳回值是 Ignore (通常由標記為 [忽略] 的按鈕傳回)。The dialog box return value is Ignore (usually sent from a button labeled Ignore).

No 7

對話方塊傳回值是 No (通常由標記為 [否] 的按鈕傳回)。The dialog box return value is No (usually sent from a button labeled No).

None 0

對話方塊傳回 NothingNothing is returned from the dialog box. 這表示強制回應 (Modal) 對話方塊繼續執行。This means that the modal dialog continues running.

OK 1

對話方塊的傳回值是 OK (通常由標記為 [確定] 的按鈕傳回)。The dialog box return value is OK (usually sent from a button labeled OK).

Retry 4

對話方塊傳回值是 Retry (通常由標記為 [重試] 的按鈕傳回)。The dialog box return value is Retry (usually sent from a button labeled Retry).

Yes 6

對話方塊傳回值是 Yes (通常由標記為 [是] 的按鈕傳回)。The dialog box return value is Yes (usually sent from a button labeled Yes).

範例

下列程式碼範例示範如何MessageBox使用的這個Show多載所支援的選項來顯示。The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. 確認字串變數ServerName是空的之後, 此範例會MessageBox顯示, 提供使用者取消作業的選項。After verifying that a string variable, ServerName, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. 如果方法的傳回值評估為 Yes, 則顯示的MessageBox表單就會關閉。 ShowIf the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.

private:
   void validateUserEntry5()
   {
      // 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 );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry5()
{

    // 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);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();

        }

    }

}
Private Sub ValidateUserEntry5()

    ' 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)

        ' 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

備註

Button.DialogResult 屬性Form.ShowDialog和方法會使用這個列舉。The Button.DialogResult property and the Form.ShowDialog method use this enumeration.

適用於

另請參閱