2
Reply

Adding custom EventArgs by inheriting class

alan

alan

Nov 21 2006 9:30 AM
2.7k
Hello. I'm stuck. I'm trying to use the menustrip control as a psuedo start menu. I'm populating the menu by reading an xml file which works fine. Where I'm stuck is that the built-in "Click" handler for the ToolStripButton only passes the Text stored on the ToolStripButton in EventArgs. I need to also pass a string holding the path of the item. I'm trying to inherit the ToolStripButton class into my own custom class that holds the path, and uses a custom handler and custom EventArgs. This is my first attempt at anything like this, so if it's wacky, please advise on the proper way to "handle" (no pun intended) it: My Custom Button Class: ********************************************************* class iLaunchMenuButton:ToolStripButton { private String appPath; public delegate void ClickageHandler(object sender, iMenuArgs ma); public event ClickageHandler Clickage; public iLaunchMenuButton() { appPath = "c:\test\test.exe"; } public void SetPath(string path) { this.appPath = path; iMenuArgs ma = new iMenuArgs(appPath); Clickage(this, ma); } public string GetPath() { return this.appPath; } } ********************************************************* My MenuArgs Class: class iMenuArgs:System.EventArgs { private string menuargs; public iMenuArgs(string args) { this.menuargs = args; } public string Menuargs() { return menuargs; } } ********************************************************* My use of the inherited class: tempMenu = new iLaunchMenuButton(); tempMenu.Image = System.Drawing.Image.FromFile(Application.StartupPath + "\\icons\\" + "gears.ico"); tempMenu.Text = "Sample Button"; tempMenu.Clickage += new iLaunchMenuButton.ClickageHandler(iMenu_Click); launchMenu.DropDownItems.Add(tempMenu); My target function: private void iMenu_Click(object sender, iMenuArgs ma) { MessageBox.Show(ma.Menuargs()); } ********************************************************* However, I am getting this error: Cannot implicitly convert type 'ininShell.iLaunchMenuButton.EventHandler' to 'System.EventHandler' on this line: tempMenu.Clickage += new iLaunchMenuButton.ClickageHandler(iMenu_Click); Can anyone help me out with my pickle? Thanks....

Answers (2)