如何解雇模态对话形式?

时间:2016-06-15 20:05:15

标签: c# .net winforms

我正在使用此示例中的代码:Messagebox with input field

用户单击表单上的按钮后,没有任何反应。表格仍然存在。我是否需要连接一些东西以使模态消失,这样我就可以获得文本框结果了?

public void ShowMyDialogBox()
{
   Form2 testDialog = new Form2();

   // Show testDialog as a modal dialog and determine if DialogResult = OK.
   if (testDialog.ShowDialog(this) == DialogResult.OK)
   {
      // Read the contents of testDialog's TextBox.
      this.txtResult.Text = testDialog.TextBox1.Text;
   }
   else
   {
      this.txtResult.Text = "Cancelled";
   }
   testDialog.Dispose();
}

1 个答案:

答案 0 :(得分:2)

要让表单关闭,您需要在Close();上的按钮点击事件中致电Form2