且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

窗口形式

更新时间:2023-10-19 17:56:16


当您单击该按钮时,检查该表单的实例是否已打开.如果不是,则打开新表格,但如果您的情况是,则将重点放在同一表格上.
例如采取那种形式的对象.进行mdichild表单的循环,并检查是否打开了具有相同名称的表单(如果是),然后将重点放在该表单上.

希望有帮助!!!! :)
Hi,
When you click on that button check instance of that form is already open or not. if no then open new form but if yes as per your case then set focus to that same one.
eg take object of that form. Take for loop of mdichild forms and check it out that form with same name is open if yes then set focus to that.

Hope this help!!!! :)


Form2 obj = new Form2();//declare as Global your navigation form.

       private void button1_Click(object sender, EventArgs e)
       {
          
           if ( obj.IsDisposed)
               obj = new Form2();           
            if (obj.WindowState == FormWindowState.Minimized)
               obj.WindowState = FormWindowState.Normal;
               else
               obj.Show();     
       }
//if this helped please vote.

<pre>




问题的根源是每次您单击按钮时,都会创建一个与其他表单不同的新表单实例.

现在有两种方法可以解决此问题.

然后声明基本或主表单为MDI表单,并检查您的代码是否为

Hi ,

Source of problem is every time you click on button there is new instance of a form is created which is different from other.

Now there is two way to solve this problem.

Declare then base or main form as a mdi form and check your code is

If Me.MdiChildren.Length > 0 Then
                For Each frmChild As Form In Me.MdiChildren
                    'Do you task here 
                Next
                
        Else
            'Code to Open form 
End If



维护表单对象和表单名称作为键的静态字典的另一种方法.在按钮上单击,检查对象是否已存在,将其激活或创建新的表单实例.



Another way to maintain a static Dictionary of object of form and form name as key. On button click check is object is already exists the activate it or create a new instance of form.