473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3650
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 found. please help!
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 parent form to do the change, but when I call 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 item's tag property to assign an identifier to...
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 item's tag property to assign an identifier to...
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 the control in the form ??? I need 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 As MenuItem In Me.Menu.menuitem" before
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, I need to hide a menuitem based on the users...
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) to the same Form (let's suppose 2 MainMenu...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.