如何:检索对话框的结果
对话框关闭后,显示该对话框的窗体可以通过引用其 DialogResult 属性,或引用调用 ShowDialog 方法的返回值,来检索对话框的结果。 然后,显示该对话框的窗体根据返回的值进行响应。
检索 DialogResult 值
将类似于下列的代码添加到显示该对话框的方法中。
通常,此代码将放在创建和显示该对话框的代码后面:
Public Sub DisplayDialog() ' Create and display an instance of the dialog box. Dim dlg as New Form() ' Show the dialog and determine the state of the ' DialogResult property for the form. If dlg.ShowDialog = DialogResult.OK Then ' Do something here to handle data from dialog box. End If End Sub
private void DisplayDialog() { // Create and display an instance of the dialog box Form dlg = new Form(); // Show the dialog and determine the state of the // DialogResult property for the form. if (dlg.ShowDialog() == DialogResult.OK ) { // Do something here to handle data from dialog box. } }
private: void DisplayDialog() { // Create and display an instance of the dialog box Form^ dlg = gcnew Form(); // Show the dialog and determine the state of the // DialogResult property for the form. if (dlg->ShowDialog() == DialogResult::OK ) { // Do something here to handle data from dialog box. } }