Showing UIElements

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
To create client business applications using current Microsoft technologies, see patterns & practices' Prism.

The Composite UI Application Block lets you create common user interface elements in a shell that components in a module can access. For example, you can create menu items that are accessible from all the SmartParts in a shell. To create and display such user interface elements (UIElements), you use the RegisterSite method of the UIExtensionSites collection of a WorkItem to register the site for a control, and the Add method of a specific UIExtensionSite to display an element.

To add and display elements on the control

  1. Call the RegisterSite method of the UIExtensionSites collection of the root WorkItem, passing the site name for the element and the control in which it will be located. You need only do this once to register the site. Afterwards, you can add multiple elements to the site by repeating steps 2, 3, and 4.
    RootWorkItem.UIExtensionSites.RegisterSite("MainMenu",
                                               Shell.MainMenuStrip);
    
  2. In the AfterShellCreated method of your class that inherits from FormShellApplication, declare a local variable of the type of element to display on the control, as shown in the following code.
    ToolStripMenuItem item = null;
    
  3. Instantiate this variable, passing in the appropriate information for the element type. The following code shows how to instantiate a menu item and specify the text to display on it. Other overloads of the constructor allow you to specify an image.
    item = new ToolStripMenuItem("Name");
    
  4. Call the Add method of the specific UIExtensionSite, passing in the element you created earlier.
    MyWorkItem.UIExtensionSites["MainMenu"].Add(item);
    
  5. Repeat steps 2 – 4, as required.


Show: