窗口形式 [英] windowsform

查看:97
本文介绍了窗口形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Windows应用程序有一点怀疑.在我的应用程序中,我保留了一个窗体作为菜单窗体,并放置了一些按钮以导航到所有其他窗体.在调试时,当我单击一个按钮时,它将显示相应的表格(例如:sales),并且我最小化了该表格.同样,当我单击该特定按钮时,它显示的是新表格(新销售表格),而不是最小化的表格.我希望最小化表单在单击按钮时处于活动状态.我怎么解决这个问题?有人可以帮我吗?

I have small doubt in my windows application. In my application I kept one form as menu form and put buttons to navigate to all other forms. On debugging when I click one button it will display corresponding form(eg: sales) and I minimized that form. Again when I click that particular button it shows a new form(new sales form) instead of that minimized one. I want the minimized form to be active when I click the button. How can I solve this problem? Can anybody help me?

推荐答案


当您单击该按钮时,检查该表单的实例是否已打开.如果不是,则打开新表格,但如果您的情况是,则将重点放在同一表格上.
例如采取那种形式的对象.进行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.


这篇关于窗口形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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