Identifying menus

  • Thread starter Adelio Stevanato
  • Start date
A

Adelio Stevanato

I am an experienced VB 3-6 developer moving to .NET.

In VB 6 i could go through the form controls collection ,
find all the menu items and using security information set-
up I could enable/dissable menu items based on their name.

DOT NOT has appeared to complicate this no end.

1. menuitem & toolbatbutton controls do not expose a name.
2. context menus are Container.Components

Real pain the the ..rs.

Is there a way of doing it in dot net.
 
E

Eric Cadwell

You could add your own properties to the controls interface through
inheritance:

public class MyMenuItem : System.Windows.Forms.MenuItem
{
string id;

public MyMenuItem(string Text, EventHandler OnClick, string ID) :
base(Text, OnClick)
{
id = ID;
}
public string ID
{
get { return id; }
set { id = value; }
}
}

Or, test with equals against the instance of the object:

MyMenuItem mymenu;

public Form1()
{
InitializeComponent();
MainMenu myMenu = new MainMenu();
MenuItem File = myMenu.MenuItems.Add("&File");
mymenu = new MyMenuItem("My Menu Item", new EventHandler(this.clicked),
"MYMENUITEM");
File.MenuItems.Add(mymenu);
}
private void clicked(object sender, EventArgs e)
{
if (sender == mymenu)
MessageBox.Show("YeeHaw");
}

HTH,
Eric Cadwell
http://www.origincontrols.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top