Практическое руководство. Извлечение результата из диалогового окна
После закрытия диалогового окна форма, которая отображает это окно, может получить результат диалогового окна путем связывания свойства 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 = 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. } }
См. также
Задачи
Практическое руководство. Создание диалоговых окон во время разработки.
Практическое руководство. Закрытие диалоговых окон и сохранение введенных пользователем данных
Основные понятия
Ввод пользовательских данных в диалоговых окнах