DialogResult

DialogResult,程式函式,是指指定標識符以指示對話框的返回值。

DialogResult

指定標識符以指示對話框的返回值。
命名空間: System.Windows.Forms
程式集: System.Windows.Forms(在 system.windows.forms.dll 中)

語法

Visual Basic(聲明)
_
Public Enumeration DialogResultVisual Basic (用法)
Dim instance As DialogResultC#
[ComVisibleAttribute(true)]
public enum DialogResultC++
[ComVisibleAttribute(true)]
public enum class DialogResultJ#
/** @attribute ComVisibleAttribute(true) */
public enum DialogResultJScript
ComVisibleAttribute(true)
public enum DialogResult

成員

成員名稱 說明
Abort 對話框的返回值是 Abort(通常從標籤為“中止”的按鈕傳送)。
Cancel 對話框的返回值是 Cancel(通常從標籤為“取消”的按鈕傳送)。
Ignore 對話框的返回值是 Ignore(通常從標籤為“忽略”的按鈕傳送)。
No 對話框的返回值是 No(通常從標籤為“否”的按鈕傳送)。
None 從對話框返回了 Nothing。這表明有模式對話框繼續運行。
OK 對話框的返回值是 OK(通常從標籤為“確定”的按鈕傳送)。
Retry 對話框的返回值是 Retry(通常從標籤為“重試”的按鈕傳送)。
Yes 對話框的返回值是 Yes(通常從標籤為“是”的按鈕傳送)。

備註

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

示例

下面的代碼示例演示如何使用受此 Show 重載支持的選項顯示一個 MessageBox。驗證字元串變數 ServerName 為空後,此示例顯示一個 MessageBox,為用戶提供取消該操作的選項。如果 Show 方法的返回值計算為 Yes,則將關閉顯示 MessageBox 的窗體。

Visual Basic 複製代碼

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

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

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

J# 複製代碼
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 Server 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
Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

相關詞條

相關搜尋

熱門詞條

聯絡我們