DialogResult 枚举

指定标识符以指示对话框的返回值。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
Public Enumeration DialogResult
用法
Dim instance As DialogResult
[ComVisibleAttribute(true)] 
public enum DialogResult
[ComVisibleAttribute(true)] 
public enum class DialogResult
/** @attribute ComVisibleAttribute(true) */ 
public enum DialogResult
ComVisibleAttribute(true) 
public enum DialogResult

成员

  成员名称 说明
由 .NET Compact Framework 支持 Abort 对话框的返回值是 Abort(通常从标签为“中止”的按钮发送)。 
由 .NET Compact Framework 支持 Cancel 对话框的返回值是 Cancel(通常从标签为“取消”的按钮发送)。 
由 .NET Compact Framework 支持 Ignore 对话框的返回值是 Ignore(通常从标签为“忽略”的按钮发送)。 
由 .NET Compact Framework 支持 No 对话框的返回值是 No(通常从标签为“否”的按钮发送)。 
由 .NET Compact Framework 支持 None 从对话框返回了 Nothing。这表明有模式对话框继续运行。 
由 .NET Compact Framework 支持 OK 对话框的返回值是 OK(通常从标签为“确定”的按钮发送)。 
由 .NET Compact Framework 支持 Retry 对话框的返回值是 Retry(通常从标签为“重试”的按钮发送)。 
由 .NET Compact Framework 支持 Yes 对话框的返回值是 Yes(通常从标签为“是”的按钮发送)。 

备注

Button.DialogResult 属性和 Form.ShowDialog 方法使用此枚举。

示例

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 = DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub
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:
   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.get_Text().get_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.Equals(DialogResult.Yes)) {
            // Closes the parent form.
            this.Close();
        }
    }
} //ValidateUserEntry5 

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

System.Windows.Forms 命名空间
Button 类
Form