Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
frmlogin ls = new frmlogin();
ls.MdiParent = this;
ls.StartPosition = FormStartPosition.CenterScreen;
ls.Show();
this.Show();

then after login click event
C#
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);

but nothing shows in main form.

Please, I need urgent help
Thanks
Masud
Software Engineer
Posted
Updated 12-Jun-10 22:30pm
v2

1 solution

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.
C#
if(ls.ShowDialog(this) == DialogResult.Ok)
{
    ShowMenu();
}
ls.Dispose();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900