Form.DialogResult Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft das Dialogergebnis für das Formular ab oder legt dieses fest.
public:
property System::Windows::Forms::DialogResult DialogResult { System::Windows::Forms::DialogResult get(); void set(System::Windows::Forms::DialogResult value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DialogResult DialogResult { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.DialogResult : System.Windows.Forms.DialogResult with get, set
Public Property DialogResult As DialogResult
Eigenschaftswert
Ein DialogResult, das das Ergebnis des Formulars bei Verwendung als Dialogfeld darstellt.
- Attribute
Ausnahmen
Der angegebene Wert liegt außerhalb des gültigen Wertebereichs.
Beispiele
Im folgenden Beispiel wird ein Formular als Dialogfeld angezeigt und ein Meldungsfeld angezeigt, das angibt, ob die Schaltfläche "OK" oder "Abbrechen" des Formulars durch Verweisen auf die DialogResult Eigenschaft des Formulars geklickt wurde.
void CreateMyForm()
{
// Create a new instance of the form.
Form^ form1 = gcnew Form;
// Create two buttons to use as the accept and cancel buttons.
Button^ button1 = gcnew Button;
Button^ button2 = gcnew Button;
// Set the text of button1 to "OK".
button1->Text = "OK";
// Set the position of the button on the form.
button1->Location = Point(10,10);
// Set the text of button2 to "Cancel".
button2->Text = "Cancel";
// Set the position of the button based on the location of button1.
button2->Location = Point(button1->Left,button1->Height + button1->Top + 10);
// Make button1's dialog result OK.
button1->DialogResult = ::DialogResult::OK;
// Make button2's dialog result Cancel.
button2->DialogResult = ::DialogResult::Cancel;
// Set the caption bar text of the form.
form1->Text = "My Dialog Box";
// Define the border style of the form to a dialog box.
form1->FormBorderStyle = ::FormBorderStyle::FixedDialog;
// Set the accept button of the form to button1.
form1->AcceptButton = button1;
// Set the cancel button of the form to button2.
form1->CancelButton = button2;
// Set the start position of the form to the center of the screen.
form1->StartPosition = FormStartPosition::CenterScreen;
// Add button1 to the form.
form1->Controls->Add( button1 );
// Add button2 to the form.
form1->Controls->Add( button2 );
// Display the form as a modal dialog box.
form1->ShowDialog();
// Determine if the OK button was clicked on the dialog box.
if ( form1->DialogResult == ::DialogResult::OK )
{
// Display a message box indicating that the OK button was clicked.
MessageBox::Show( "The OK button on the form was clicked." );
// Optional: Call the Dispose method when you are finished with the dialog box.
delete form1;
}
else
{
// Display a message box indicating that the Cancel button was clicked.
MessageBox::Show( "The Cancel button on the form was clicked." );
// Optional: Call the Dispose method when you are finished with the dialog box.
delete form1;
}
}
public void CreateMyForm()
{
// Create a new instance of the form.
Form form1 = new Form();
// Create two buttons to use as the accept and cancel buttons.
Button button1 = new Button ();
Button button2 = new Button ();
// Set the text of button1 to "OK".
button1.Text = "OK";
// Set the position of the button on the form.
button1.Location = new Point (10, 10);
// Set the text of button2 to "Cancel".
button2.Text = "Cancel";
// Set the position of the button based on the location of button1.
button2.Location
= new Point (button1.Left, button1.Height + button1.Top + 10);
// Make button1's dialog result OK.
button1.DialogResult = DialogResult.OK;
// Make button2's dialog result Cancel.
button2.DialogResult = DialogResult.Cancel;
// Set the caption bar text of the form.
form1.Text = "My Dialog Box";
// Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
// Set the accept button of the form to button1.
form1.AcceptButton = button1;
// Set the cancel button of the form to button2.
form1.CancelButton = button2;
// Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen;
// Add button1 to the form.
form1.Controls.Add(button1);
// Add button2 to the form.
form1.Controls.Add(button2);
// Display the form as a modal dialog box.
form1.ShowDialog();
// Determine if the OK button was clicked on the dialog box.
if (form1.DialogResult == DialogResult.OK)
{
// Display a message box indicating that the OK button was clicked.
MessageBox.Show("The OK button on the form was clicked.");
// Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose();
}
else
{
// Display a message box indicating that the Cancel button was clicked.
MessageBox.Show("The Cancel button on the form was clicked.");
// Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose();
}
}
Public Sub CreateMyForm()
' Create a new instance of the form.
Dim form1 As New Form()
' Create two buttons to use as the accept and cancel buttons.
Dim button1 As New Button()
Dim button2 As New Button()
' Set the text of button1 to "OK".
button1.Text = "OK"
' Set the position of the button on the form.
button1.Location = New Point(10, 10)
' Set the text of button2 to "Cancel".
button2.Text = "Cancel"
' Set the position of the button based on the location of button1.
button2.Location = New Point(button1.Left, button1.Height + button1.Top + 10)
' Make button1's dialog result OK.
button1.DialogResult = DialogResult.OK
' Make button2's dialog result Cancel.
button2.DialogResult = DialogResult.Cancel
' Set the caption bar text of the form.
form1.Text = "My Dialog Box"
' Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog
' Set the accept button of the form to button1.
form1.AcceptButton = button1
' Set the cancel button of the form to button2.
form1.CancelButton = button2
' Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen
' Add button1 to the form.
form1.Controls.Add(button1)
' Add button2 to the form.
form1.Controls.Add(button2)
' Display the form as a modal dialog box.
form1.ShowDialog()
' Determine if the OK button was clicked on the dialog box.
If form1.DialogResult = DialogResult.OK Then
' Display a message box indicating that the OK button was clicked.
MessageBox.Show("The OK button on the form was clicked.")
' Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose
' Display a message box indicating that the Cancel button was clicked.
Else
MessageBox.Show("The Cancel button on the form was clicked.")
' Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose
End If
End Sub
Hinweise
Das Dialogfeldergebnis eines Formulars ist der Wert, der aus dem Formular zurückgegeben wird, wenn es als modales Dialogfeld angezeigt wird. Wenn das Formular als Dialogfeld angezeigt wird, legt das Festlegen dieser Eigenschaft mit einem Wert aus der DialogResult Enumeration den Wert des Dialogfeldergebnisses für das Formular fest, blendet das modale Dialogfeld aus, und gibt das Steuerelement an das aufrufende Formular zurück. Diese Eigenschaft wird in der Regel durch die DialogResult Eigenschaft eines Button Steuerelements im Formular festgelegt. Wenn der Benutzer auf das Button Steuerelement klickt, wird der Wert, der der DialogResult Eigenschaft Button des Formulars zugewiesen ist, zugewiesen DialogResult .
Wenn ein Formular als modales Dialogfeld angezeigt wird, wird das Formular ausgeblendet, und die Eigenschaft wird auf die DialogResult Schaltfläche "Schließen" (die Schaltfläche mit einem X in der oberen rechten Ecke des Formulars) festgelegtDialogResult.Cancel
. Die Close Methode wird nicht automatisch aufgerufen, wenn der Benutzer auf die Schaltfläche "Schließen " eines Dialogfelds klickt oder den Wert der DialogResult Eigenschaft festlegt. Stattdessen ist das Formular ausgeblendet und kann erneut angezeigt werden, ohne eine neue Instanz des Dialogfelds zu erstellen. Aufgrund dieses Verhaltens müssen Sie die Dispose Methode des Formulars aufrufen, wenn das Formular von Ihrer Anwendung nicht mehr benötigt wird.
Sie können diese Eigenschaft verwenden, um zu bestimmen, wie ein Dialogfeld geschlossen wird, um die im Dialogfeld ausgeführten Aktionen ordnungsgemäß zu verarbeiten.
Hinweis
Sie können den Wert überschreiben, der der DialogResult Eigenschaft zugewiesen ist, wenn der Benutzer auf die Schaltfläche "Schließen " klickt, indem Sie die DialogResult Eigenschaft in einem Ereignishandler für das Closing Ereignis des Formulars festlegen.
Hinweis
Wenn ein Objekt Form als modusloses Fenster angezeigt wird, gibt der von der Eigenschaft zurückgegebene Wert möglicherweise keinen Wert zurück, der DialogResult dem Formular zugewiesen ist, da die Ressourcen des Formulars automatisch freigegeben werden, wenn das Formular geschlossen wird.