How to: Hide or Disable a Menu Item on a Context Menu
Outlook Developer Reference |
The following context menu events provide a reference to the CommandBar object that represents the context menu to be displayed:
- AttachmentContextMenuDisplay
- FolderContextMenuDisplay
- ItemContextMenuDisplay
- ShortcutContextMenuDisplay
- StoreContextMenuDisplay
- ViewContextMenuDisplay
You can set the Visible and Enabled properties of command bar controls, such as the CommandBarButton object, to respectively hide or disable menu items on a context menu. If you want to prevent the display of menu items provided by Outlook, you should hide, rather than remove, such menu items by setting the Visible property for menu items to be hidden to False.
The sample temporarily modifies the context menu for a store, such as an Exchange mailbox or an Outlook data (.pst) file, so that it cannot be moved to the Favorites navigation group within Outlook. The sample does this by alternatively hiding or disabling the Add to Favorite Folders menu item within the store context menu. The sample performs the following actions:
- The sample first iterates through each control in the CommandBar object provided by the CommandBar parameter of the StoreContextMenuDisplay event.
- If the Add to Favorite Folders menu item, a CommandBarButton with an Id property value of 7888, is present in the context menu, the sample then sets the Visible property of that menu item to the value of the variable,
blnHiddenOrDisabled
. - It then sets the Enabled property of that menu item to the opposite value of the variable,
blnHiddenOrDisabled
. The sample sets the Visible and Enabled properties in this way so that the menu item is either not visible, or visible but disabled, alternating between the two states each time the event occurs in Outlook. - After completing the iteration, the sample finally sets the
blnHiddenOrDisabled
Boolean variable to its opposite value, so that the sample can alternate between the two states on each subsequent StoreContextMenuDisplay event.
|