动态菜单条问题 [英] Dynamic Menu Strip Problem

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

问题描述


我在创建动态菜单栏时遇到问题.
我的MDI父容器表单名称main
和登录表单名称frmlogin.
从主加载事件开始的事件

Hi,
I am fetching problem in Creating Dynamic Menu strip.
My mdi parent container form Name main,
and login form name frmlogin.
starting form main load event

frmlogin ls = new frmlogin();
ls.MdiParent = this;
ls.StartPosition = FormStartPosition.CenterScreen;
ls.Show();
this.Show();


然后登录后单击事件


then after login click event

main ms=new main();
ms.showmenu();
this.Close();


然后是主要表格方法


then main form method

MenuStrip mainMenu = new MenuStrip();

ToolStripMenuItem itemFile = new ToolStripMenuItem("&File");
itemFile.DropDownItems.Add("&New");
itemFile.DropDownItems.Add("&Open", null, MenuItem_Click);
itemFile.DropDownItems.Add("-");
itemFile.DropDownItems.Add("&Save");
itemFile.DropDownItems.Add("Save &As ...");
itemFile.DropDownItems.Add("-");
itemFile.DropDownItems.Add("E&xit", null, CloseApp_Click);
mainMenu.Items.Add(itemFile);

ToolStripMenuItem itemHelp = new ToolStripMenuItem("&Help");
itemHelp.DropDownItems.Add("A&bout");
itemHelp.DropDownItems.Add("Management");
mainMenu.Items.Add(itemHelp);
this.Controls.Add(mainMenu);


但没有显示任何主要形式.

拜托,我需要紧急帮助
谢谢
Masud
软件工程师


but nothing shows in main form.

Please, I need urgent help
Thanks
Masud
Software Engineer

推荐答案

首先,请问您的问题使用正确的格式更具可读性吗?始终在代码(< pre></pre>)周围使用[code block].

其次,避免为任何对象使用名称mainMain方法在任何C#程序(和C/C ++)中都有特殊的意义,将其用作名称有时会以灾难告终.我建议FormMain或类似的名称.

看来您的问题出在中间代码块中,您在其中创建一个全新的main并在其上调用ShowMenu();.您真正想要的是在现有main实例上调用ShowMenu.

纠正这种情况的最简单方法是使用ShowDialog显示登录表单,而不必理会MdiChild.然后,您可以设置登录表单的DialogResult并在主表单中对其进行测试.
Firstly, see how much more readable your question is using the correct formatting? always use the [code block] around code (<pre></pre>).

Secondly, avoid the name main for any object! The Main method has a special significance in any C# program (and C/C++), using it as a name will end in disaster at some point. I would suggest FormMain or something similar.

It seems that your problem is in the middle code block where you are creating a whole new main and calling ShowMenu(); on that. What you really want is to call ShowMenu on the existing main instance.

The easiest way to rectify this in your situation is to show the login form using ShowDialog and forget about the MdiChild thing for it. You can then set the DialogResult of the login form and test that in the main form.
if(ls.ShowDialog(this) == DialogResult.Ok)
{
    ShowMenu();
}
ls.Dispose();


这篇关于动态菜单条问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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