I'm stuck on this (menuitems)

M

M

<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items and sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 
A

AlexS

M,

you can test sender reference, which you get in handler as parameter, for
which menu item invoked the handler. Just cast it to MenuItem and you can
access all properties and methods. You can use Text, Mnemonic or Shortcut at
least.

HTH
Alex
 
M

M

Thanks for answering.

I know I can cast it to the menuitem and get the text but I can only get its
text (a, b or c) but I cannot get its parents text.

I'm guessing that I should add an event handler to the second level menu
items to catch the Popup event. Then record the current active items text.

Something along those lines, I'm not sure though because its not clear right
now.

I am hoping someone would read it and go "oh you just need to do this...."
or like many of my past posts I'll think of the answer about an hour after I
send the original post but that has yet to happen.


AlexS said:
M,

you can test sender reference, which you get in handler as parameter, for
which menu item invoked the handler. Just cast it to MenuItem and you can
access all properties and methods. You can use Text, Mnemonic or Shortcut at
least.

HTH
Alex

M said:
<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items and sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 
A

AlexS

M,

you can get reference to parent menu using MenuItem.Parent property. From
parent menu you can go up using IsParent and GetMainMenu

I am not sure now what is your problem

HTH
Alex

M said:
Thanks for answering.

I know I can cast it to the menuitem and get the text but I can only get its
text (a, b or c) but I cannot get its parents text.

I'm guessing that I should add an event handler to the second level menu
items to catch the Popup event. Then record the current active items text.

Something along those lines, I'm not sure though because its not clear right
now.

I am hoping someone would read it and go "oh you just need to do this...."
or like many of my past posts I'll think of the answer about an hour after I
send the original post but that has yet to happen.


AlexS said:
M,

you can test sender reference, which you get in handler as parameter, for
which menu item invoked the handler. Just cast it to MenuItem and you can
access all properties and methods. You can use Text, Mnemonic or
Shortcut
at
least.

HTH
Alex

M said:
<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items
and
sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 
J

Jacob Munk-Stander

Hi,
I'm just wondering... what you're adding now is a reference to the same menu
item to all the subsubmenuitems. Try replacing your MyPopUpSubSubMenu with

public class MyPopUpSubSubMenu : ContextMenu
{
static int i = 0;
public MyPopUpSubSubMenu()
{
MenuItems.Add(new MenuItem("a" + i++));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

and you'll see that there's only one reference being added (namely the
same). Instead try using

MenuItems[0].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[1].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[2].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[3].MergeMenu(new MyPopUpSubSubMenu());

in MyPopUpSubMenu and you'll see the difference.

As far as I can see this creates a problem regarding the Parent property. I
tried coding something different:

ContextMenu popup = new ContextMenu();

popup.MenuItems.Add(new MenuItem("A"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("1"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("2"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("3"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("4"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("a"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("b"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("c"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("d"));

popup.MenuItems.Add(new MenuItem("B"));
popup.MenuItems.Add(new MenuItem("C"));
popup.MenuItems.Add(new MenuItem("D"));

and used the following in the WhoseCallingMe function to traverse from child
to parent:

public void WhoseCallingMe(object sender, System.EventArgs e)
{
MenuItem menuItem = (MenuItem) sender;

string path = "";

while(menuItem.GetType() == menuItem.Parent.GetType())
{
path = "-> " + menuItem.Text + path;

menuItem = (MenuItem) menuItem.Parent;
}

path = "-> " + menuItem.Text + path;

MessageBox.Show(path);
}


If you know the menuitems on beforehand the individual menu items could get
their own event handler, though that could lead up to quite a lot of event
handlers.

What exactly are you trying to do? It sounds as if you want to create your
own ContextMenu class?

Hope this helps a bit!

--
Yours sincerely,
Jacob Munk-Stander | http://jacob.munk-stander.dk


M said:
<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items and sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 
M

M

ok. The other responder Jacob showed me the light.

I was having a mental block and didn't make the connection to the parent
item being a menuitem itself. I kept thinking 'ok I have the parent item
which is a menu, how do I figure out which menuitem was the active one."

Now it is clear.

Thanks for you help though

Best Regards
M

AlexS said:
M,

you can get reference to parent menu using MenuItem.Parent property. From
parent menu you can go up using IsParent and GetMainMenu

I am not sure now what is your problem

HTH
Alex

M said:
Thanks for answering.

I know I can cast it to the menuitem and get the text but I can only get its
text (a, b or c) but I cannot get its parents text.

I'm guessing that I should add an event handler to the second level menu
items to catch the Popup event. Then record the current active items text.

Something along those lines, I'm not sure though because its not clear right
now.

I am hoping someone would read it and go "oh you just need to do this...."
or like many of my past posts I'll think of the answer about an hour
after
I
send the original post but that has yet to happen.


AlexS said:
M,

you can test sender reference, which you get in handler as parameter, for
which menu item invoked the handler. Just cast it to MenuItem and you can
access all properties and methods. You can use Text, Mnemonic or
Shortcut
at
least.

HTH
Alex

<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items and
sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 
M

M

ok great, I've got it now. Thanks

This line > menuItem = (MenuItem) menuItem.Parent;

cleared it up for me. I kept thinking that I have the parent but how do I
determine which menuitem was the 'active' one. I forget it was a menuitem
itself.

And thanks for pointing out the reference to the same menu item to all the
subsubmenuitems, that would of cause some problems.

Right now I know the menu items but at some point I'd like to make the
second tier menuitems added dynamically as the users see fit but that's down
the road a little bit.

Actually I'm going to have one handler for all the items. In the one handler
I needed to determine which second level item (and possibly first level too)
called me so it can open the correct form.

Thanks for your help. I do appreciate it.

Best Regards,
M


Jacob Munk-Stander said:
Hi,
I'm just wondering... what you're adding now is a reference to the same menu
item to all the subsubmenuitems. Try replacing your MyPopUpSubSubMenu with

public class MyPopUpSubSubMenu : ContextMenu
{
static int i = 0;
public MyPopUpSubSubMenu()
{
MenuItems.Add(new MenuItem("a" + i++));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

and you'll see that there's only one reference being added (namely the
same). Instead try using

MenuItems[0].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[1].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[2].MergeMenu(new MyPopUpSubSubMenu());
MenuItems[3].MergeMenu(new MyPopUpSubSubMenu());

in MyPopUpSubMenu and you'll see the difference.

As far as I can see this creates a problem regarding the Parent property. I
tried coding something different:

ContextMenu popup = new ContextMenu();

popup.MenuItems.Add(new MenuItem("A"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("1"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("2"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("3"));
popup.MenuItems[0].MenuItems.Add(new MenuItem("4"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("a"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("b"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("c"));
popup.MenuItems[0].MenuItems[0].MenuItems.Add(new MenuItem("d"));

popup.MenuItems.Add(new MenuItem("B"));
popup.MenuItems.Add(new MenuItem("C"));
popup.MenuItems.Add(new MenuItem("D"));

and used the following in the WhoseCallingMe function to traverse from child
to parent:

public void WhoseCallingMe(object sender, System.EventArgs e)
{
MenuItem menuItem = (MenuItem) sender;

string path = "";

while(menuItem.GetType() == menuItem.Parent.GetType())
{
path = "-> " + menuItem.Text + path;

menuItem = (MenuItem) menuItem.Parent;
}

path = "-> " + menuItem.Text + path;

MessageBox.Show(path);
}


If you know the menuitems on beforehand the individual menu items could get
their own event handler, though that could lead up to quite a lot of event
handlers.

What exactly are you trying to do? It sounds as if you want to create your
own ContextMenu class?

Hope this helps a bit!

--
Yours sincerely,
Jacob Munk-Stander | http://jacob.munk-stander.dk


M said:
<see code snippet below>

I'm trying to determine how I can tell when a user clicks
A->1->a OR
A->3->b OR
D->4->c ...

While in the handler I cannot determine what sequence of menu items and sub
menu items brought me there.

If anyone has any ideas or can show me in code what I should do I would
highly appreciate it.

Thanks




public class MyPopUpSubSubMenu : ContextMenu
{
public MyPopUpSubSubMenu()
{

MenuItems.Add(new MenuItem("a"));
MenuItems.Add(new MenuItem("b"));
MenuItems.Add(new MenuItem("c"));
MenuItems.Add(new MenuItem("d"));
}
};

public class MyPopUpSubMenu : ContextMenu
{
public MyPopUpSubMenu()
{
MenuItems.Add(new MenuItem("1"));
MenuItems.Add(new MenuItem("2"));
MenuItems.Add(new MenuItem("3"));
MenuItems.Add(new MenuItem("4"));

m_SubSubMenu = new MyPopUpSubSubMenu();

MenuItems[0].MergeMenu(m_SubSubMenu);
MenuItems[1].MergeMenu(m_SubSubMenu);
MenuItems[2].MergeMenu(m_SubSubMenu);
MenuItems[3].MergeMenu(m_SubSubMenu);
}

public MyPopUpSubSubMenu m_SubSubMenu;

};

public class MyPopUpMenu : ContextMenu
{
public MyPopUpMenu()
{
MenuItems.Add(new MenuItem("A"));
MenuItems.Add(new MenuItem("B"));
MenuItems.Add(new MenuItem("C"));
MenuItems.Add(new MenuItem("D"));

m_SubMenu = new MyPopUpSubMenu();

MenuItems[0].MergeMenu(m_SubMenu);
MenuItems[1].MergeMenu(m_SubMenu);
MenuItems[2].MergeMenu(m_SubMenu);
MenuItems[3].MergeMenu(m_SubMenu);
}

public MyPopUpSubMenu m_SubMenu;

};

public class Form1 : System.Windows.Forms.Form
{
public MyPopUpMenu myPopUpMenu;

private void Form1_Load(object sender, System.EventArgs e)
{

myPopUpMenu = new MyPopUpMenu();
//myPopUpMenu.MenuItems[0].MenuItems[0].Popup += new
EventHandler(this.WhoseCallingMe);

myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[0].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[1].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[2].Click += new
EventHandler(this.WhoseCallingMe);
myPopUpMenu.MenuItems[0].MenuItems[0].MenuItems[3].Click += new
EventHandler(this.WhoseCallingMe);


this.ContextMenu = myPopUpMenu;
}


public void WhoseCallingMe(object sender, System.EventArgs e)
{
MessageBox.Show("How can I tell who called me?");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top