Hello,
writing my C# program I have noticed that, when I click on a menu item that has some submenu items, the click event isn't generated (I have written a procedure to handle the menu item click event but, even if I have put a breakpoint at the beginning of the handling procedure code, when I click the program doesn't stop).
Is it normal? Is there a way to catch the click event of a menu item with sub menu items and execute the relative handling procedure?
Thank you very much
P.S.: Here I have attached a code snippet that highlights the problem: when you click on the mi1 menu item, the messagebox "You have clicked on MenuItem1" doesn't appear...
writing my C# program I have noticed that, when I click on a menu item that has some submenu items, the click event isn't generated (I have written a procedure to handle the menu item click event but, even if I have put a breakpoint at the beginning of the handling procedure code, when I click the program doesn't stop).
Is it normal? Is there a way to catch the click event of a menu item with sub menu items and execute the relative handling procedure?
Thank you very much
P.S.: Here I have attached a code snippet that highlights the problem: when you click on the mi1 menu item, the messagebox "You have clicked on MenuItem1" doesn't appear...
Code:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
class TestMenuItem : Form
{
private MenuItem miFile, mi1, mi1_1, mi1_2;
public static void Main()
{
Application.Run(new TestMenuItem());
}
public TestMenuItem()
{
miFile = new MenuItem("&File");
mi1 = new MenuItem("&MenuItem1");
mi1.Click += new EventHandler(mi1_Click);
mi1_1 = new MenuItem("M&enuItem1_1");
mi1_1.Click += new EventHandler(mi1_1_Click);
mi1_2 = new MenuItem("Me&nuItem1_2");
mi1_2.Click += new EventHandler(mi1_2_Click);
Menu = new MainMenu();
Menu.MenuItems.AddRange(new MenuItem[] {miFile});
miFile.MenuItems.AddRange(new MenuItem[] {mi1});
mi1.MenuItems.AddRange(new MenuItem[] {mi1_1, mi1_2});
}
private void mi1_Click(object sender, EventArgs e)
{
MessageBox.Show("You have clicked on MenuItem1");
}
private void mi1_1_Click(object sender, EventArgs e)
{
MessageBox.Show("You have clicked on MenuItem1_1");
}
private void mi1_2_Click(object sender, EventArgs e)
{
MessageBox.Show("You have clicked on MenuItem1_2");
}
}