Custom Property in MenuItem

adwaitjoshi

Active member
Joined
Dec 29, 2005
Messages
38
Programming Experience
1-3
Is it possible to add a custom property to the MenuItem something called as say FunctionName where I am going to store a function name to be executed when the button is clicked.?

If not then I will maintain a array where I can store the menu name and function name. Is it possible to get a menuitem name from the code?? I dont see a .Name property for a menuitem. I see a Text property but not a name property.
 
If you want to have different functions executed with the same menu you should as well change the text property so that the user knows what action he will perform.

If VB 2005 you can identify the menu displayed name in the event handler sub by using the following code :

VB.NET:
[SIZE=2][COLOR=#0000ff]
CType[/COLOR][/SIZE][SIZE=2](sender, ToolStripMenuItem).Text
[/SIZE]

You can then chose what action to do by using a select case.
 
At a time the menu will only execute one function. But when I change the Function Name at design time, I will simply change that and the behaviour of the menu option will change.
 
You could inherit the MenuItem class and add whatever additional members you want. Where are these function names coming from? Are you hard-coding them or are they coming from an outside source? If you are hard-coding them then you should simply create a Click event handler for the MenuItem and call the method. If they are coming from an outside source then things are not as easy as just calling the method. You cannot just call a method if you have its name in a string variable. You would need to use reflection to call the method via a MethodInfo object.
 
Back
Top