|
-
Sep 11th, 2004, 11:37 AM
#1
Thread Starter
Frenzied Member
Adding EventHandler - am I doing this right?
I'm trying to build a context menu on the fly and add an EvendHandler so something happens when I click my MenuItem. Problem is, nothing happens when I click the MenuItem. Am I missing something in this code?
Code:
ContextMenu cm = new ContextMenu();
MenuItem miNewRadioMessage = new MenuItem("&Radio Message");
this.miNewRadioMessage.Click += new System.EventHandler(this.CreateRadioMessage);
cm.MenuItems.Add(miNewRadioMessage);
cm.Show(axMap, new Point(mouseX, mouseY));
private void CreateRadioMessage(object sender, EventArgs e)
{
MessageBox.Show("click");
}
Thanks,
Mike
-
Sep 11th, 2004, 07:10 PM
#2
<?="Moderator"?>
I don't known if this affects it but all the examples I have seen state the action in the function name
eg
Code:
this.mnuFile_Exit.Click += new System.EventHandler(this.mnuFile_Click);
/* menu event code */
private void mnuFile_Click(object sender, EventArgs e)
{
MessageBox.Show("You Click the File Menu Item!");
}
-
Sep 12th, 2004, 06:00 PM
#3
you could always try inheriting the menu items in a custom class then add your events in it , also you need to trigger the event before anything will happen , eg:
PHP Code:
public class mnuItem : MenuItem
{
public delegate void createMessage(object sender, EventArgs e);
public event createMessage CreateRadioMessage;
public void CreateMessage(object sender, EventArgs e)
{
CreateRadioMessage(sender , e);
}
}
to add a menuitem / test it in a form ...
PHP Code:
private void button1_Click(object sender, System.EventArgs e)
{
mnuItem mnu = new mnuItem();
mnu.Text = "i'm a menu item";
mnu.CreateRadioMessage +=new inherit_menu.mnuItem.createMessage(mnu_CreateRadioMessage);
contextMenu1.MenuItems.Add(mnu);
mnu.CreateMessage((object)"test",null);
}
private void mnu_CreateRadioMessage(object sender, EventArgs e)
{
MessageBox.Show(Convert.ToString(sender));
}
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 12th, 2004, 08:06 PM
#4
Thread Starter
Frenzied Member
Thanks for the replies. I'm not sure what's going on, but when I change the owner of the menu from "axMap" - which is a MapPoint ActiveX control to "this", things seem to work fine.
Thanks,
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|