我不明白菜单的工作原理 [英] I don't understand how the menu works

查看:61
本文介绍了我不明白菜单的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我现在正在窗口基础程序上工作,但是我需要一个帮助.当我再次单击该菜单时从菜单中打开一个窗口时,我得到了已经在c#中打开的窗口.

hi now i m working on window base program but i need a help.when i open a window from menu when i click on that menu again then i got that window that is already open in c#

推荐答案

您需要将from实例存储为类级变量.运行菜单处理程序时,请检查变量是否为null,如果是则仅打开新窗口.然后将新的表单实例存储在变量中,以备后用.
您还需要处理FormClosed事件,以将保存的实例返回为空.
You need to store the from instance as a class level variable. When you run the menu handler, check if the variable is null and only open the new window if it is. Then store the new form instance in the variable for later.
You will also want to handle the form FormClosed event to return the saved instance to null.


您必须创建一个声明了所有全局变量以及该文件或类的类或文件.已在整个应用程序中进行了评估
您的所有子表格都将在那里声明.
You have to create a class or file where all the global variables have been declared and that file or class has been assessed in whole application
your all child form will be declared there.
public class GlobalVar
{
    private static MyChildForm _My;
    public MyChildForm MyChild
    {
        get
        {
             if(_my == null)
             {
                 _my = new MyChildForm();
                 return _my; 
              }
             else
             {
                 return _my;
             }
         }
    }
}



现在在您的菜单项click event中编写此代码



now in your menu item click event write this code

GlobalVar glob = new GlobalVar();

private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
      glob.MyChild.Show();
}


这篇关于我不明白菜单的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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