DialogResult 列舉

定義

指定識別項以指示對話方塊的傳回值。

C#
[System.Runtime.InteropServices.ComVisible(true)]
public enum DialogResult
C#
public enum DialogResult
繼承
DialogResult
屬性

欄位

Abort 3

對話方塊傳回值是 Abort (通常由標記為 [中止] 的按鈕傳回)。

Cancel 2

對話方塊傳回值是 Cancel (通常由標記為 [取消] 的按鈕傳回)。

Continue 11

對話方塊傳回值為 Continue (通常從標示為 Continue) 的按鈕傳送。

Ignore 5

對話方塊傳回值是 Ignore (通常由標記為 [忽略] 的按鈕傳回)。

No 7

對話方塊傳回值是 No (通常由標記為 [否] 的按鈕傳回)。

None 0

對話方塊傳回 Nothing。 這表示強制回應 (Modal) 對話方塊繼續執行。

OK 1

對話方塊的傳回值是 OK (通常由標記為 [確定] 的按鈕傳回)。

Retry 4

對話方塊傳回值是 Retry (通常由標記為 [重試] 的按鈕傳回)。

TryAgain 10

對話方塊傳回值為 [再試 (通常會從標示為 [再試) ] 的按鈕傳送。

Yes 6

對話方塊傳回值是 Yes (通常由標記為 [是] 的按鈕傳回)。

範例

下列程式碼範例示範如何使用 這個 多載 Show 所支援的選項來顯示 MessageBox 。 確認字串變數 ServerName 為 空白之後,此範例會顯示 , MessageBox 為使用者提供取消作業的選項。 Show如果方法的傳回值評估為 [是],則會關閉顯示 MessageBox 的表單。

C#
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();
        }
    }
}

備註

屬性 Button.DialogResult 和 方法會 Form.ShowDialog 使用此列舉。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱