473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find a MenuItem's name, or, there's no more Tag property

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 each menu entry, then used that identifier as an index into a
collection populated at user login in order to determine the item's visibility.

Now, for some reason there's no tag property for .NET MenuItems, so I'm looking for
some way to accomplish what I was able to do in VB6. If I could get access to the
menu name assigned at design time that could work, but I can't see how to do that.
It's not available at run time via the menu item's type.

The sample code in help has hideous If/Then/ElseIf structures like:

If menuitem is mnuFile Then
...
elseif menuitem is mnuEdit then
...
elseif...

But there has to be a better way to uniquely identify a menuitem at run time.

I suppose I could derive a class from MenuItem and define my own tag or other
identifier property, but then I wouldn't be able to use that class in the menu
designer.

Is it possible to discover the specific instance of the menuitem via reflection
somehow?

Nov 20 '05
15 2475
On Sun, 30 May 2004 15:32:14 +0100, "Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote:
How about creating an extender to add an Identifier property to a menu item?
You'll get the extra property and will still be able to use standard
MenuItems.
I'll just write one now and add it to the Menus section on my website.


Thank you.

I tried your MenuIdentifier class, but it didn't seem to work. Perhaps I am doing
something wrong (and I certainly don't claim to understand the extenderprovide r
class), but I included your class in my project, and the "Identifier " property does
not show up on a menuitem, either at run time or design time.

Is there some other plumbing I need to hook up this extender?
Nov 20 '05 #11
Well I don't know what the problem could be since it works a treat here.
Once I drop a MenuIdentifier component on my form all the Menu Items are
extended with
Identifier On MenuIdentifier1
It was very quickly thrown together and the value is initially an empty
string. I tested it by changing the value to that of the text, but you can
change it to any string value. I then tested it wth the following code:
\\\\\\\\\\\\\\\ \\\\\\\
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
CheckMenuItems( Me.Menu)
End Sub

Sub CheckMenuItems( ByVal Menu_Item As Menu)
Dim s() As String = {"Cut", "Open"}
For Each ITEM As MenuItem In Menu_Item.MenuI tems
If Array.BinarySea rch(s, _
MenuIdentifier1 .GetIdentifier( ITEM).ToString) >= 0 Then
ITEM.Enabled = False
End If
CheckMenuItems( ITEM)
Next
End Sub
/////////////////////////
This resulted in the Cut and Open menuitems being disabled.

Do you have a MenuIdentifier component sitting next to your MainMenu
component?

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/index.html
"Jeff Mason" <je******@comca st.net> wrote in message
news:e6******** *************** *********@4ax.c om...
On Sun, 30 May 2004 15:32:14 +0100, "Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote:
How about creating an extender to add an Identifier property to a menu item?You'll get the extra property and will still be able to use standard
MenuItems.
I'll just write one now and add it to the Menus section on my website.
Thank you.

I tried your MenuIdentifier class, but it didn't seem to work. Perhaps I

am doing something wrong (and I certainly don't claim to understand the extenderprovide r class), but I included your class in my project, and the "Identifier " property does not show up on a menuitem, either at run time or design time.

Is there some other plumbing I need to hook up this extender?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 27/05/2004
Nov 20 '05 #12
After adding the class to your project compile and then add the
MenuIdentifier to the toolbox. You can then drop one on your form at
designtime and the extended property should show up on all menuitems.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/index.html
Thank you.

I tried your MenuIdentifier class, but it didn't seem to work. Perhaps I am doing something wrong (and I certainly don't claim to understand the extenderprovide r class), but I included your class in my project, and the "Identifier " property does not show up on a menuitem, either at run time or design time.

Is there some other plumbing I need to hook up this extender?

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 27/05/2004
Nov 20 '05 #13
On Mon, 31 May 2004 00:08:44 +0100, "Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote:
Once I drop a MenuIdentifier component on my form all the Menu Items are
extended with
Identifier On MenuIdentifier1


That was the piece I was missing. Thank you. It indeed "works a treat".
Nov 20 '05 #14
You're welcome.

I have modified the source to give a more meaningful name. You will now get
Tag on MenuTagger1.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/index.html
"Jeff Mason" <je******@comca st.net> wrote in message
news:m9******** *************** *********@4ax.c om...
On Mon, 31 May 2004 00:08:44 +0100, "Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote:
Once I drop a MenuIdentifier component on my form all the Menu Items are
extended with
Identifier On MenuIdentifier1


That was the piece I was missing. Thank you. It indeed "works a treat".

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.691 / Virus Database: 452 - Release Date: 26/05/2004
Nov 20 '05 #15
Jeff,
This is a large project with many many menu entries yet to be developed, so the menu designer is pretty important to me.
What I normally do is derived from MenuItem as the article suggests. Then I
carefully modify the "Windows Form Designer generated code" section to
replace all "System.Windows .Forms.MenuItem " with my derived MenuItem class.
Using "Edit - Replace in Files" if needed...

I normally reserve the property extender for when I need to add a property
to a variety of classes on a form and cannot (choose not to) extend the
individual classes...

Hope this helps
Jay

"Jeff Mason" <je******@comca st.net> wrote in message
news:39******** *************** *********@4ax.c om... On 30 May 2004 01:32:36 +0200, hi************* **@gmx.at (Herfried K. Wagner [MVP]) wrote:
<URL:http://groups.google.de/groups?selm=...K2MSFTNGP10.ph x.gbl>
Thank you for your response. Your link suggests I derive a class from MenuItem to add a property to handle this. But, as I said in my original post:
I suppose I could derive a class from MenuItem and define my own tag or otheridentifier property, but then I wouldn't be able to use that class in the menudesigner.
This is a large project with many many menu entries yet to be developed,

so the menu designer is pretty important to me.

Is there another way to identify the menu items in a form?

Nov 20 '05 #16

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

Similar topics

9
3675
by: Rakesh | last post by:
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?
4
4989
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
6224
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 method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
4
1833
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 each menu entry, then used that identifier as an index into a collection populated at user login in order to determine the item's visibility. Now, for some reason there's no tag property for .NET MenuItems, so I'm looking for some way to...
6
1543
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 Me.mnuXXX.Enabled = false during run-time Anyone know how can do that ??
2
1248
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
2396
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 role. The problem is that I can't seem to get access to the menuitem. I can't get it with code like: MDIParent.mnuAdministrator.Visible = true MDIParent is the name of the form I gave. This is also the Startup form (in the project settings) if this...
3
3567
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
2166
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 objects). It is possible (and it's my case) that these 2 MainMenu objects use some different MenuItem objects and some identical MenuItem objects. For example, let's assume that: mainMenu1 contains miFile, miEdit, miHelp mainMenu2 contains miFile,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.