Take the 2-minute tour ×

I want to display a message box when any person clicks on the menu item which is not enabled I have tried the following coding but it is not displaying the message box.


private void updateFineDetailsToolStripMenuItem_Click(object sender, EventArgs e)
    if (updateFineDetailsToolStripMenuItem.Enabled == true)
        frmUpdateFineDetails objUpdateFineDetails = new frmUpdateFineDetails();
        objUpdateFineDetails.MdiParent = this;
    else if (updateFineDetailsToolStripMenuItem.Enabled == false)
        MessageBox.Show("Unauthorized Person");

By default I have set the enabled status to false and when the form loads I am checking whether the user is administrator, if the user is admin then this menu item will be enabled for all other user who logs into the application the above menu item has to be disabled.

Please note that the above coding does not generate any error, but it does not even display the messagebox as unauthorized person.

Can anybody help me out in performing this task?

Thanks in advance!

share|improve this question
add comment

5 Answers

The whole idea of disabling a menu item or a button is to prevent the user from interacting with it. Typically the control will also be rendered in a way so that this becomes clear to the user. If you want to prevent the user from taking certain actions, for instance based on whether the user is an administrator or not, you can use one of three approaches:

  • Keep the control enabled and inform unauthorized users that the function is not available if he or she invokes it
  • Disable the control
  • Hide the control

In the later two cases there is no interaction, since the user cannot invoke the command. I usually tend to prefer to hide the command, if the access to it is role based (meaning that if I don't have access to the command when I start the application, it will not happen at any point while running it), or disabling it if the availability of the command is related to data state.

share|improve this answer
add comment

As I understand, a disabled menu item does not raise Click events.

share|improve this answer
Thanks for your prompt reply! But is it possible to display the MessageBox when other users click on it? –  Sheetal Jul 25 '09 at 7:13
add comment

If you need to display the error message then enable the menu item.

If admin clicks then default action occurs and if other users click show a message box and prevent the default action.

From your code I think you can do this just by enabling the menu item.

share|improve this answer
add comment

Disabling a menu item isn't a cosmetic display issue, it does just what you'd expect from the term - it disables the menu item.

When disabled, the menu item is effectively inert - it will not raise the click event, and there's no (straightforward) way to make it do so.

I can guess at your motivations - to explain to your users why the particular menu item is unavailable to them - but you'll need to find a different approach, one that works with the system, not against it.

Some possible approaches ...

  • Leave the menu item disabled, allowing the user to select it - you can then make a role based choice on how to handle the event.
  • Disable the menu item and provide feedback elsewhere in your UI telling the user what level of access they have.
  • Display a tooltip with the reason for disabling the control
  • Leave the menu item enabled, but change it's display to look inactive (this is hard to achieve 100%); this will allow the events to fire and your handler to be invoked
  • Create a separate "Explain" menu item, perhaps on the "Help" menu; when invoked, all disabled menu items become enabled, and will explain to the user why the command is unavailable.
  • Some systems display a line of help text relevant to the highlighted menu item on the status bar - you could leverage this to explain availability: "Maintain customer details (requires Administrator role)"
share|improve this answer
add comment

a disabled control does not raise Click events. you should simulate that state! for example:

  1. enable menu item
  2. change menu item's forecolor to SystemColors.GrayText
  3. save state of item in item's tag (enable or disable)
  4. if click event raised, first check item's tag
  5. change menu item's forecolor to normal fore color if enabled item.
share|improve this answer
add comment

Your Answer


