how to create dynamic event handlers

M

mike

i'm building an desktop windows app in C#. the main menu for the
application will be different depending on the admin rights of the
user. i've built the entire app. in delphi and i simply activated or
deactivated the menu items in that case, but all the menu items are
visble. i'm hoping / thinking that with .NET, i can dynamically
generate the click events for the dynamically generated menu, so that
only the menu items, that a particular user has access to will show,
along with their events. is this possible?
 
G

Guest

Hope I have understood your Question correctly , this might be the solution
When menu is created , put the following code on run time
toolBarLabel.Click += new System.EventHandler(ToolBarLabel.Click);
 
J

John A. Bailo

mike said:
i'm building an desktop windows app in C#. the main menu for the
application will be different depending on the admin rights of the
user. i've built the entire app. in delphi and i simply activated or
deactivated the menu items in that case, but all the menu items are
visble. i'm hoping / thinking that with .NET, i can dynamically
generate the click events for the dynamically generated menu, so that
only the menu items, that a particular user has access to will show,
along with their events. is this possible?

You can always do that with the += and =- to add or remove handlers.

Or you could have menu items and .Enable them as needed.

I do this in one of my clients that has an Edit and Read mode:


if(ConfigurationSettings.AppSettings["Mode"].Equals("Edit"))
edit=true;

switch(nlevel){
case 1:

//(A) Add a RowBayLevel node.
this.menuItem1.Enabled=edit; //add
this.menuItem3.Enabled=false; //delete
this.menuItem2.Enabled=false; //change
this.menuItem4.Enabled=false; //move


break;
 

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