Click here to Skip to main content
16,018,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!!

I wrote a code to create a "MENU" in C#.The problem i have is menu is not visible.But the code works in a another form.I can't understand what has happened.Is there any option in the form to make invisible the menu??.I will be realy thankful if any one can give me a hint..

sameera
Posted

1 solution

1) Change your username: Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know

2) Did you add the menu to the form? I.e. Did you set the Form.MainMenuStrip Property to the menu?

"Thanks.
But i still have that problem with that specific form..Here is the code which i used for both projects.One is working,one is not."
private void set_menus() {
    mnumain = new MainMenu();

    MenuItem proc1 = new MenuItem("&Test Procedure");
    proc1.MenuItems.Add(new MenuItem("&Before Pouring", new EventHandler(this.proc1BeforePouring_clicked)));
    proc1.MenuItems.Add(new MenuItem("&After Pouring", new EventHandler(this.proc1AfterPouring_clicked)));
    proc1.MenuItems.Add(new MenuItem("&Exit", new EventHandler(this.proc1Exit_clicked)));
    this.Menu = mnumain;
}
private void proc1BeforePouring_clicked(object sender, EventArgs e)
{

}
private void proc1AfterPouring_clicked(object sender, EventArgs e)
{

}
private void proc1Exit_clicked(object sender, EventArgs e)
{
    this.Close();
}


You need to add the menuitem to the menu...
proc1.MenuItems.Add(new MenuItem("&Exit", new EventHandler(this.proc1Exit_clicked)));
mnumain.MenuItems.Add(proc1);  //<<<----- ADD THIS LINE
this.Menu = mnumain;
 
Share this answer
 
v2
Comments
Sameera Fonseka 17-Apr-11 4:19am    
Thanks.
But i still have that problem with that specific form..Here is the code which i used for both projects.One is working,one is not.

private void set_menus() {
mnumain = new MainMenu();

MenuItem proc1 = new MenuItem("&Test Procedure");
proc1.MenuItems.Add(new MenuItem("&Before Pouring", new EventHandler(this.proc1BeforePouring_clicked)));
proc1.MenuItems.Add(new MenuItem("&After Pouring", new EventHandler(this.proc1AfterPouring_clicked)));
proc1.MenuItems.Add(new MenuItem("&Exit", new EventHandler(this.proc1Exit_clicked)));
this.Menu = mnumain;
}

private void proc1BeforePouring_clicked(object sender, EventArgs e)
{

}

private void proc1AfterPouring_clicked(object sender, EventArgs e)
{

}

private void proc1Exit_clicked(object sender, EventArgs e)
{
this.Close();
}
OriginalGriff 17-Apr-11 4:28am    
Answer updated
Sameera Fonseka 17-Apr-11 5:35am    
Hello!
Thank you very much.Then it started working.But the code i posted worked without the line you pointed out.That is still a big mystery to me.Don't know why it is happening like that.Any way thank you very much for your kind attention on this matter.Thank you.

Yours Sincerely
sameera
OriginalGriff 17-Apr-11 5:39am    
You are welcome!
Sergey Alexandrovich Kryukov 17-Apr-11 14:38pm    
My 5, mostly for patience :-)
--SA

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