Click here to Skip to main content
15,896,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a C#.net project.I want to enable or disable the menu as per the user who sign in....Please give a nice solution.I don't get the toolstripmenuitem.,means the submenu items in the menu.
Posted

Hi
By using below code u will know the user is admin or not....
C#
WindowsIdentity  identity = 
      WindowsIdentity.GetCurrent();
   WindowsPrincipal principal = 
      new WindowsPrincipal (identity);
   return principal.IsInRole 
      (WindowsBuiltInRole.Administrator);
 
Share this answer
 
if you have different menus for different roles
then place menus in different div tags. Based on your signedin user change the visibility of corresponding div ..........
 
Share this answer
 
v2
Start with the Menu[^] class, and use the Enabled property of individual MenuItems[^] as required.
 
Share this answer
 
The easiest way is to handle the ToolMenuStripItem DropDownOpening event. The sender parameter tells you which menu is opening:
C#
private void editToolStripMenuItem_DropDownOpening( object sender, EventArgs e )
    {
    ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
    tsmi.DropDownItems[0].Enabled = false;
    }
Would disable the first item of which ever menu is opened.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900