开发者

How to pause a form in Visual C# until another form is closed

In my program I will press a bu开发者_运维技巧tton, and it will load form2. I do not want the program in form1 to continue running until the user closes form2. Then program execution continues in form1 right after the line that loads form2.


i think you want to show a modalled dialog.

public class MyForm1 : Form
{

  public void ShowDialog2()
  {
    MyForm2 form2 = new MyForm2();
    form2.ShowDialog(this);
  }
}


You can use

Form.ShowDialog Method (IWin32Window)


You call the .ShowDialog function on the form you want to show.

.Show simply shows the new form. Calling .ShowDialog causes the calling form to block until execution returns from the shown form.

The result returned from the call to .ShowDialog will tell you if the user hit 'Okay' or 'No' or cancelled the form by clicking the x in the corner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜