如何在基于窗口的C#项目中打开另一个表单之前强制关闭表单 [英] How to make a form close mandatory before opening another in window based C# project

查看:59
本文介绍了如何在基于窗口的C#项目中打开另一个表单之前强制关闭表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于Windows的c#项目中工作;我带了一个菜单条并添加了菜单名称.在单击特定菜单时,将打开所需的表格.
现在,我想做一件事,即某人打开了一个表单,直到关闭该表单,他们却无法打开另一个表单.因此,这意味着在关闭特定表格后,他们可以访问其他表格.
谁能指导我该怎么做?

在此先感谢

I am working on windows base c# project; i have taken a menu strip and added menu name. While click on a particular menu desired form is opening.
Now i want to do one thing that while someone has opened one form until the form is closed they cannot open another form. So that means after closing that particular form they can access other form.
Can anyone please guide me how can i do this?

Thanks in advance

推荐答案



在菜单项的单击事件上,在代码下方添加,

Hi,

On Menu Item Click event add below Code,

if(Application.OpenForms.Count > 0)
{
   bool flag = false;
   foreach(Form frm in Application.OpenForms)
   {
      if(frm.Name == "frmMenu")
      {
          //Ignoring the MDI form or the form with menu
      }
      else
      {
          flag = true;
          break;
      }
   }

   if(flag)
   {
       MessageBox.Show("Kindly close the current Form");
   }
   else
   {
      Form2 frm = new Form2();
      frm.Show();
      //Open the new form
   }
}
else
{
   Form2 frm = new Form2();
      frm.Show();
      //Open the new form
}



希望对您有所帮助.



hope it helps.


windowsform1 f1 = new windowsform1();
f1.showdialog();

windowsform1 f1=new windowsform1();
f1.showdialog();

Check this.


form1 f1 = new form1();
f1.showdialog();
使用这个
form1 f1= new form1();
f1.showdialog();
use this


这篇关于如何在基于窗口的C#项目中打开另一个表单之前强制关闭表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆