472,330 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

MenuItem Name property

Hi,

I am able to obtain a MenuItem object's Name property @
design-time, but am not able to get the same @ run-
time...why?

And since MenuItem doesn't inherit from Control class,
it's not even supposed to be available @ design-time
right?

Thanks in advance
Rakesh

Nov 15 '05 #1
9 3576
Rakesh,

The designer accomplishes the name property by actually extending your
class and then hosting that in the property grid. The Name property is then
expose off that derived class. The Name property is really the name of the
variable, which you should know already. If you don't, then you will need
to place the identifier of some sort on the MenuItem (by extending the
MenuItem class and attaching your information).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rakesh" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
Hi,

I am able to obtain a MenuItem object's Name property @
design-time, but am not able to get the same @ run-
time...why?

And since MenuItem doesn't inherit from Control class,
it's not even supposed to be available @ design-time
right?

Thanks in advance
Rakesh

Nov 15 '05 #2
I have the same problem

I am trying to build an MDI template other developers can customize later.
I want to include code on the mainform that will enable or disable menuitems added later given only their names. the function will be called from a child form. These menuitems do not exist at design time for the template
I have code that works using the text property but this does not allow for common names. E.g. File/new and Window/new both get disabled or enabled at the same time.
Nov 15 '05 #3
It sounds like I have a similar problem

I am working on an MDI template and I want to place code on the mainform to enable or disable menuitems.

The first problem is I must cope with menu items that do not exist while I am designing the template, they can be added later by another developer. I do not want to make the menu items public and open the existing items to tampering

The trigger to disable an item will originate from a child form which will not know about the menuitem objects and must pass a string to identify an item

I have code that works using the Text property but it won't allow for common item names. e.g. it thinks File/new and Window/new are the same thing

the second problem is processing the menu selections. If you want to process the menu click on the child form and cannot pass it an object, how do you identify the menu item? Remembering that the item in question was added to a derived form not the original template
----- Nicholas Paldino [.NET/C# MVP] wrote: ----

Rakesh

The designer accomplishes the name property by actually extending you
class and then hosting that in the property grid. The Name property is the
expose off that derived class. The Name property is really the name of th
variable, which you should know already. If you don't, then you will nee
to place the identifier of some sort on the MenuItem (by extending th
MenuItem class and attaching your information)

What are you trying to do
--
- Nicholas Paldino [.NET/C# MVP
- mv*@spam.guard.caspershouse.co

"Rakesh" <an*******@discussions.microsoft.com> wrote in messag
news:0b****************************@phx.gbl..
Hi
I am able to obtain a MenuItem object's Name property

design-time, but am not able to get the same @ run
time...why
And since MenuItem doesn't inherit from Control class

it's not even supposed to be available @ design-tim
right
Thanks in advanc

Rakes

Nov 15 '05 #4
to***********@gmx.de (Torsten Kraus) wrote in message news:<eb**************************@posting.google. com>...
hi there,

i've had the same problem. Unfortunally MenuItem and ToolBarButton
have no Name property. But the name Property is only the Name of the
Variable/Field.
So you can figure out the Name of a ToolBarButton or MenuItem using
Reflection.

The following Sample retreive the Name of a given ToolBarButton:

public static string GetToolBarButtonName(System.Windows.Forms.Form
frmParent, System.Windows.Forms.ToolBarButton tbButton)
{
FieldInfo[] fields =
frmParent.GetType().GetFields(System.Reflection.Bi ndingFlags.NonPublic|System.Reflection.BindingFlag s.Public|System.Reflection.BindingFlags.Static|Sys tem.Reflection.BindingFlags.Instance);
foreach(FieldInfo field in fields)
{
if (field.GetValue(frmParent) == tbButton)
return field.Name;
}
return "";
}

ciao
Torsten


Hi

The code above works fine for Menu object, but not MenuItem object.

Any ideas?

Thx,

Carel
Nov 16 '05 #5
I've had the same problem as Rakesh

I've got a Menu in my application that will be changing from time to time as I revise the application throughout the remainder of it's Alpha stage, and possibly during it's Beta stage

I've got upwards of 50 MenuItems under one particular Menu selection. I'm using a try-catch-end try to catch several exceptions that are sometimes thrown. Instead of using 50+ subProcedure declarations, I did one declaration that handles all of the menuitems that I need. However, when I went to do a select case decision structure, I found out the hard way that .name is not a property, but a protected or private field that was never made accesible via a string readonly property. I think the .NET developers need to fix this, as MANY controls have a string readonly property for access at run time

Dolphin Incarnate
Nov 16 '05 #6
to***********@gmx.de (Torsten Kraus) wrote in message news:<eb**************************@posting.google. com>...
hi there,

i've had the same problem. Unfortunally MenuItem and ToolBarButton
have no Name property. But the name Property is only the Name of the
Variable/Field.
So you can figure out the Name of a ToolBarButton or MenuItem using
Reflection.

The following Sample retreive the Name of a given ToolBarButton:

public static string GetToolBarButtonName(System.Windows.Forms.Form
frmParent, System.Windows.Forms.ToolBarButton tbButton)
{
FieldInfo[] fields =
frmParent.GetType().GetFields(System.Reflection.Bi ndingFlags.NonPublic|System.Reflection.BindingFlag s.Public|System.Reflection.BindingFlags.Static|Sys tem.Reflection.BindingFlags.Instance);
foreach(FieldInfo field in fields)
{
if (field.GetValue(frmParent) == tbButton)
return field.Name;
}
return "";
}

ciao
Torsten


Hi

The code above works fine for Menu object, but not MenuItem object.

Any ideas?

Thx,

Carel
Nov 16 '05 #7
I've had the same problem as Rakesh

I've got a Menu in my application that will be changing from time to time as I revise the application throughout the remainder of it's Alpha stage, and possibly during it's Beta stage

I've got upwards of 50 MenuItems under one particular Menu selection. I'm using a try-catch-end try to catch several exceptions that are sometimes thrown. Instead of using 50+ subProcedure declarations, I did one declaration that handles all of the menuitems that I need. However, when I went to do a select case decision structure, I found out the hard way that .name is not a property, but a protected or private field that was never made accesible via a string readonly property. I think the .NET developers need to fix this, as MANY controls have a string readonly property for access at run time

Dolphin Incarnate
Nov 16 '05 #8
to***********@gmx.de (Torsten Kraus) wrote in message news:<eb**************************@posting.google. com>...
hi there,

i've had the same problem. Unfortunally MenuItem and ToolBarButton
have no Name property. But the name Property is only the Name of the
Variable/Field.
So you can figure out the Name of a ToolBarButton or MenuItem using
Reflection.

The following Sample retreive the Name of a given ToolBarButton:

public static string GetToolBarButtonName(System.Windows.Forms.Form
frmParent, System.Windows.Forms.ToolBarButton tbButton)
{
FieldInfo[] fields =
frmParent.GetType().GetFields(System.Reflection.Bi ndingFlags.NonPublic|System.Reflection.BindingFlag s.Public|System.Reflection.BindingFlags.Static|Sys tem.Reflection.BindingFlags.Instance);
foreach(FieldInfo field in fields)
{
if (field.GetValue(frmParent) == tbButton)
return field.Name;
}
return "";
}

ciao
Torsten


Hi

The code above works fine for Menu object, but not MenuItem object.

Any ideas?

Thx,

Carel
Nov 16 '05 #9
I've had the same problem as Rakesh

I've got a Menu in my application that will be changing from time to time as I revise the application throughout the remainder of it's Alpha stage, and possibly during it's Beta stage

I've got upwards of 50 MenuItems under one particular Menu selection. I'm using a try-catch-end try to catch several exceptions that are sometimes thrown. Instead of using 50+ subProcedure declarations, I did one declaration that handles all of the menuitems that I need. However, when I went to do a select case decision structure, I found out the hard way that .name is not a property, but a protected or private field that was never made accesible via a string readonly property. I think the .NET developers need to fix this, as MANY controls have a string readonly property for access at run time

Dolphin Incarnate
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tony | last post by:
like this, foreach (MenuItem item in this.mainMenu1.MenuItems) { //some code //I want to get the menuitem's name here! } No name property ...
6
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the...
15
by: Jeff Mason | last post by:
I have an application where I need to set certain menu items invisible based on a user privilege. We did a sinmlar thing in VB6 and used the menu...
4
by: Jeff Mason | last post by:
I have an application where I need to set certain menu items invisible based on a user privilege. We did a sinmlar thing in VB6 and used the menu...
6
by: Agnes | last post by:
dim c as controls for each c in me.controls messagebox.show(c.name) next c I found that the menu time didn't show up ?? It didn't belongs to...
2
by: Agnes | last post by:
I know how to get the Menuitem's TEXT . BUT I need to get the names , Does anyone know how to do ?? Thanks I try That " For Each FileMenuItem...
1
by: Michael | last post by:
Hi Everyone, I seem to be having a problem accessing a menuitem on the MDIParent from a child form. From a login (frmSecurity -child form) screen,...
3
by: Jason Huang | last post by:
Hi, Would someone tell me how to get a MenuItem's Name in a C# Windows Form? Thanks for help. Jason
2
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course)...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.