Newsflash

Add your items to Windows Explorer Shell context menu - it never was easier: Windows Explorer Shell Context Menu v7.14 was released

Read more...
 

Full Vista support appended

Read more...
 
Home arrow Archive arrow Design-Time Context Menu Verbs
Design-Time Context Menu Verbs PDF Print E-mail
Design-Time Integration - Design-Time Context Menu Verbs

This article is about the Design-Time Context Menu Verbs and custom items appending to Windows Explorer Shell context menu. To take the design-time-only property even further, it's possible to add items to a component's design-time context menu. These items are called verbs, and ShowBorder would make a fine addition to our clock control's verb menu.

Add an item to Windows Explorer Shell context menu easily – How ?

 

 

 Add an item to Windows Explorer Shell context menu with the Windows Explorer Shell Context Menu

 

  Insert an entry to Windows Explorer Shell context menu easily with Windows Explorer Shell Context Menu. This powerful .Net component for your own, custom items adding to Windows Explorer Shell context menu will add all your application entries to Explorer Shell context menu. This .Net component with full C# , C++ and VB.NET support include detailed C# and VB.NET samples, tutorials and support all you may need :

  • Add all your items to Windows Explorer Shell context menu to be shown on any Windows operating system (all OS are supported – Windows XP, Vista, Windows x64 , etc.)
  • Add items to Windows Explorer Shell context menu to be shown in any way - with your custom caption and your custom icon, as separator or sub-menu
  • Add items to Windows Explorer Shell context menu to be shown for all types of files or shown only for files of particular type (for example, only for .PDF .TXT , .MP3,.WMA,.AAC , .MPG media files)
  • Add your program items to Windows Explorer Shell context menu, sub-menus, sub-sub-menus, sub-menus of unlimited depth and even more


Windows Explorer Shell Context Menu - is a powerful .Net component that support all you need to insert all your application items to the Windows Explorer Shell context menu - in a fast and a very easy way. Add your items to Windows Explorer Shell context menu right now – add items to context menu fast , easy and exactly as you want :

 Add items To Windows Explorer Shell Context Menus in a very easy way with Windows Explorer Shell Context Menu

 

Adding to the verb menu requires that we further augment the custom designer class:

public class ClockControlDesigner : ControlDesigner {
  ...
  public override DesignerVerbCollection Verbs {
   get {
     // Return new list of context menu items
     DesignerVerbCollection verbs =
       new DesignerVerbCollection();
     showBorderVerb =
       new DesignerVerb(
       GetVerbText(),
       new EventHandler(ShowBorderClicked));
     verbs.Add(showBorderVerb);
     return verbs;
     }
   }
   ...
 }

The Verbs override is queried by the Designer shell for a list of DesignerVerbs to insert into the component's context menu. Because this method works only for Windows 95 / Windows 98 (not on XP, Vista, x64 - 64-bit Windows), to add items to Windows Explorer Shell context menu you should use, according to Microsoft guidelines, appropriate .Net component - Windows Explorer Shell Context Menu. Each DesignerVerb in the DesignerVerbCollection takes a string name value plus the event handler that responds to verb selection. In our case, this is ShowBorderClicked:

public class ClockControlDesigner : ControlDesigner {
  ...
  void ShowBorderClicked(object sender, EventArgs e) {
     // Toggle property value
     ShowBorder = !ShowBorder;
     }
   ...
   }

This handler simply toggles the ShowBorder property. However, because the verb menu for each component is cached, it takes extra code to show the current state of the ShowBorder property in the verb menu:

public class ClockControlDesigner : ControlDesigner {
  ...
  bool ShowBorder {
    get { return showBorder; }
   
    set {
    // Change property value
    PropertyDescriptor property =
    TypeDescriptor.GetProperties(typeof(ClockControl))["ShowBorder"];
    this.RaiseComponentChanging(property);
    showBorder = value;
   this.RaiseComponentChanged(property, !showBorder, showBorder);
   
    // Toggle Show/Hide Border verb entry in context menu
    IMenuCommandService   menuService =
    (IMenuCommandService)this.GetService
    (typeof(IMenuCommandService));
    if( menuService != null ) {
   
      // Re-create Show/Hide Border verb
      if( menuService.Verbs.IndexOf(showBorderVerb) >= 0 ) {
        menuService.Verbs.Remove(showBorderVerb);
        showBorderVerb =
          new DesignerVerb(
          GetVerbText(),
          new EventHandler(ShowBorderClicked));
        menuService.Verbs.Add(showBorderVerb);
      }
    }
   
   // Update clock UI
   clockControl.Invalidate ();
   }
  }
  ...
  }

ShowBorder now performs two distinct operations. First, the property value is updated between calls to RaiseComponentChanging and RaiseComponentChanged, helper functions that wrap calls to the designer host's IComponentChangeService. The second part of ShowBorder re-creates the Show/Hide Border verb to reflect the new property value. This manual intervention is required because the Verbs property is called only when a component is selected on the form. In our case, "Show/Hide Border" could be toggled any number of times after the control has been selected.

Fortunately, after the Verbs property has delivered its DesignerVerbCollection payload to the Designer, it's possible to update it via the designer host's IMenuCommandService. Unfortunately, because the Text property is read-only, you can't implement a simple property change. Instead, the verb must be re-created and re-associated with ShowBorderClicked every time the ShowBorder property is updated.

On top of adding Show/Hide Border to the context menu, .NET throws in a clickable link for each verb, located on the Property Browser above the property description bar. It illustrates all three options, including the original editable property.

Custom designers allow you to augment an application developer's design-time experience even further than simply adding the effects to the Property Browser. Developers can change how a control renders itself, controlling the properties, methods, and events that are available at design time and augmenting a component's verbs.
 
< Prev   Next >
© 2010 Add items to context menu, add entries, add programs and commands -
Easily with Windows Explorer Shell Context Menu .NET Component (C#, VB, C++, VB.NET).
All product and company names are trademarks or registered trademarks of their respective owners.