Como: Retornar o resultado de uma caixa de diálogo
This example shows how to retrieve the dialog result for a window that is opened by calling ShowDialog.
Exemplo
Before a dialog box closes, its DialogResult property should be set with a Nullable<T> Boolean that indicates how the user closed the dialog box. This value is returned by ShowDialog to allow client code to determine how the dialog box was closed and, consequently, how to process the result.
Observação
DialogResult can only be set if a window was opened by calling ShowDialog.
Dim dialogBoxWithResult As New DialogBoxWithResult()
' Open dialog box and retrieve dialog result when ShowDialog returns
Dim dialogResult? As Boolean = dialogBoxWithResult.ShowDialog()
Select Case dialogResult
Case True
' User accepted dialog box
Case False
' User canceled dialog box
Case Else
' Indeterminate
End Select
DialogBoxWithResult dialogBoxWithResult = new DialogBoxWithResult();
// Open dialog box and retrieve dialog result when ShowDialog returns
bool? dialogResult = dialogBoxWithResult.ShowDialog();
switch (dialogResult)
{
case true:
// User accepted dialog box
break;
case false:
// User canceled dialog box
break;
default:
// Indeterminate
break;
}
Segurança
Calling ShowDialog requires permission to use all windows and user input events without restriction.