Identifying menus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adelio Stevanato

    #1

    Identifying menus

    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.Compo nents

    Real pain the the ..rs.

    Is there a way of doing it in dot net.
  • Eric Cadwell

    #2
    Re: Identifying menus

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

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

    public MyMenuItem(stri ng 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()
    {
    InitializeCompo nent();
    MainMenu myMenu = new MainMenu();
    MenuItem File = myMenu.MenuItem s.Add("&File");
    mymenu = new MyMenuItem("My Menu Item", new EventHandler(th is.clicked),
    "MYMENUITEM ");
    File.MenuItems. Add(mymenu);
    }
    private void clicked(object sender, EventArgs e)
    {
    if (sender == mymenu)
    MessageBox.Show ("YeeHaw");
    }

    HTH,
    Eric Cadwell



    Comment

    Working...