Click here to Skip to main content
12,625,607 members (34,471 online)
Click here to Skip to main content
Add your own
alternative version


214 bookmarked

Creating an Extensible User Interface with .NET, Part 1

, 15 Dec 2002
Rate this:
Please Sign up or sign in to vote.
An architecture for extending the User Interface of a program via plug-in components.


Many times it can be desirable to extend or enhance the User Interface (UI) of a program after it has been deployed. Usually this means redeploying the entire application. This document describes a “plug in” architecture that allows for the UI to be extended at any time. An example of a program with an extensible UI is the Microsoft Management Console (MMC) and its associated snap-ins.


There is one main requirement that your program must meet before this architecture can be considered.

  • There should be NO interaction between UI plug-ins. This does not mean they cannot share a common data structure or business objects, but each UI plug-in should not try to make direct calls to other plug-ins.

In this architecture all UI elements are contained in a set of plug-ins based upon the System.Windows.Forms.UserControl class. All plug-ins are described in a configuration file, and loaded at runtime. Extending the UI is accomplished by creating a new plug-in and adding the appropriate entries to the config file.

Some of the advantages of this architecture are:

  • Independent development of different UI elements. For example, if you are developing a Personal Information Manager (PIM), one person could be working on the "Appointments/Calender" UI, while another works on the "Contacts" UI.
  • Application control. You could restrict the functionality of the application based upon the user's name or the user's roll or purchased options.
  • You can add new UI elements at any time. In the PIM example above, you could add a "Diary" UI after the application has been distributed.

The architecture consists of 3 parts:

  1. A “shell” application that handles the loading and navigation between the plug-ins.
  2. A base class that supplies all communications between the “shell” and the plug-ins.
  3. The individual UI plug-ins themselves.

The shell

At startup the shell application reads a configuration file to get the names and locations for each UI plug-in. It then uses reflection to load each plug-in. In the screen shots below, the Shell application contains a ListBox used to navigate between plug-ins, and a Panel in which the plug-ins are loaded.

Here is an example of a “shell” with 2 plug-ins loaded. The ListBox on the left is used to select between each plug-in, while the panel on the right will display the plug-in when it is made visible.

Clicking on "PlugIn1" made the plug-in visible.

And then clicking on "PlugIn Number 2" makes it visible in the panel.

The Tabbed Shell application shows another way of navigation:

Here is the Tabbed Shell after it has been loaded.

And here it is after "PlugIn Number 2" has been selected.

How the Shell finds the plug-ins.

The plug-ins to be loaded at runtime are listed in an XML file named config.xml.

<?xml version="1.0" encoding="utf-8" ?>
  <PlugIn Location="E:\ExtensibleUI\OurControls\bin\Debug\OurControls.dll" 
  <PlugIn Location="E:\ExtensibleUI\OurControls\bin\Debug\OurControls.dll" 

In the form load event, the config.xml file is loaded into a DataSet via ReadXml. Then it iterates each DataRow calling AddPlugin with the “location” and “name” of the plug-in.

private void Form1_Load(object sender, System.EventArgs e)
    DataSet ds = new DataSet();
    foreach(DataRow dr in ds.Tables["Plug-In"].Rows)

Two examples of the AddPlugIn code.

The AddPlugIn loads the assembly containing the plug-in and creates an instance of it. It also adds the plug-in to the ListBox. When a new item in the list box is selected, we need to hide the current plug-in, and show the new selection.

// Load and add a plug-in to the panel1 control
// Also set the list box to navigate between plugins.
private void AddPlugIn(string Location, string ControlName)
    Assembly ControlLib;
    PlugIn NewPlugIn;
    // Load the assembly.
    ControlLib = Assembly.LoadFrom(Location);

    // Now create the plugin.
    NewPlugIn = (PlugIn)ControlLib.CreateInstance(ControlName);
    NewPlugIn.Location = new System.Drawing.Point(0, 0);
    NewPlugIn.Dock = DockStyle.Fill;
    NewPlugIn.Visible = false;
    // Add it to the panel, note that its Visible property is false.
    // Set up the ClickHandler
    NewPlugIn.Clicked += new PlugInLib.ClickHandler(Control_Clicked);
    // Add the plugin to the listBox, listBox will use ToString to
    // get the text to display.


private PlugIn CurrentPlugIn;

// When a new item in the listBox is selected,
// hide the current plugin and show the new.
private void listBox1_SelectedIndexChanged(object sender, 
                                           System.EventArgs e)
        CurrentPlugIn.Visible = false;
    CurrentPlugIn = (PlugIn)listBox1.SelectedItem;
    CurrentPlugIn.Visible = true;

The AddPlugIn for the Tabbed Shell application is only slightly different. The Tabbed Shell application needs no navigation code because it is handled by the TabControl.

// Load and add a plug-in to the TabControl1 control
private void AddPlugIn(string Location, string ControlName)
    Assembly ControlLib;
    PlugIn NewPlugIn;
    // Load the assembly.
    ControlLib = Assembly.LoadFrom(Location);

    // Now create the plugin.
    NewPlugIn = (PlugIn)ControlLib.CreateInstance(ControlName);
    NewPlugIn.Location = new System.Drawing.Point(0, 0);
    NewPlugIn.Dock = DockStyle.Fill;
    NewPlugIn.Visible = true;
    // Create a new TabPage.
    TabPage newPage = new TabPage();
    // Set the text on the tabPage with the PlugIn Caption.
    newPage.Text = NewPlugIn.Caption;
    // Add the PlugIn to the TabPage.
    // Add the page to the tabControl.
    // Set up the ClickHandler
    NewPlugIn.Clicked += new PlugInLib.ClickHandler(Control_Clicked);

The PlugIn base blass

The PlugIn base class is based upon the System.Windows.Forms.UserControl class and extends it to provide predefined events, methods, and properties that each plug-in can use to communicate with the shell applications. In this example a Clicked event, a Caption property, and a TestFunction method are predefined. In addition, ToString is overridden to return the Caption instead of the object name.

using System;
using System.Windows.Forms;

namespace PlugInLib
    /// <span class="code-SummaryComment"><summary>

Creating a UI plug-in.

  1. Use Visual Studio to create a new “Windows Control Library”.
  2. Add a reference to the PlugInLib that contains the plug-in base class.
  3. Change the name of the user control from UserControl1 to something more descriptive.
  4. Add the using directive for the PlugInLib.
  5. Change the base class for the user control from System.Windows.Forms.UserControl to PlugIn.
  6. Connect any events that you want to send to the shell applications.
  7. Add the necessary overrides for calls from the shell to the plug-in.
  8. Construct your UI as you would for any other UserControl.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using PlugInLib;            // <---Add using for the plug-In base class

namespace OurControls
    /// <span class="code-SummaryComment"><summary>


With this architecture, the interaction between the plug-ins and the shell should be well defined and limited. In the PlugIn base class example shown above, the only real interaction between the shell and plug-in is the Caption property. Another possible interaction would be for the shell to load a common data structure that is passed to each plug-in when it is loaded.

You can add new plug-ins at any time, simply by creating a new plug-in and adding the appropriate entries to the config.xml file.


In the demo zip available in the downloads section, config.xml file is located in both the Release and Debug directories of the two "Shell" applications. These files contain the absolute pathname to the OurControls.dll including a drive letter. You will need to modify these paths for your local system.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Keith Jacquemin
Web Developer
United States United States
I am a senior software developer located in Phoenix, AZ. I have a wide range of experience using Microsoft development technologies and have clung to the bleeding edge of their developments tools since Windows 3.1. I am now lacerating myself on .Net.

I am currently available for any contract or permanent assignments.

You may also be interested in...


Comments and Discussions

Generalhelp neede!!! Pin
er.atirek16-Jun-09 7:56
memberer.atirek16-Jun-09 7:56 
JokeRe: help neede!!! Pin
smslt15-Oct-09 2:46
membersmslt15-Oct-09 2:46 
GeneralDesigner support for plugins Pin
waveangle10-Dec-05 23:19
memberwaveangle10-Dec-05 23:19 
QuestionWhy require a config file? Pin
Greg Donovan26-Aug-05 16:06
memberGreg Donovan26-Aug-05 16:06 
AnswerRe: Why require a config file? Pin
Keith Jacquemin27-Aug-05 7:04
memberKeith Jacquemin27-Aug-05 7:04 
GeneralDependencies Pin
BigBenDk27-Jul-05 6:39
memberBigBenDk27-Jul-05 6:39 
GeneralRe: Dependencies Pin
Keith Jacquemin27-Jul-05 15:44
memberKeith Jacquemin27-Jul-05 15:44 
GeneralRe: Dependencies Pin
BigBenDk2-Aug-05 2:39
memberBigBenDk2-Aug-05 2:39 
GeneralRe: Dependencies Pin
richerm22-Sep-05 4:01
memberricherm22-Sep-05 4:01 
Generalhelp needed Pin
raghavendra .K27-Feb-05 19:11
memberraghavendra .K27-Feb-05 19:11 
General?how to create database connection inside of DLL Pin
MBCMDR15-Oct-04 8:54
memberMBCMDR15-Oct-04 8:54 
GeneralOurControls Pin
Dennis Bay5-Oct-04 10:08
sussDennis Bay5-Oct-04 10:08 
GeneralRe: OurControls Pin
MBCMDR5-Oct-04 10:16
memberMBCMDR5-Oct-04 10:16 
GeneralRe: OurControls Pin
Keith Jacquemin5-Oct-04 20:28
memberKeith Jacquemin5-Oct-04 20:28 
GeneralRe: OurControls Pin
dbay16-Oct-04 6:37
memberdbay16-Oct-04 6:37 
GeneralAccess error when loading the plug-in Pin
Sivankoil23-Jul-04 8:04
memberSivankoil23-Jul-04 8:04 
GeneralYet Another Alternative Pin
mooman_fl17-Mar-04 20:11
membermooman_fl17-Mar-04 20:11 
GeneralRe: Yet Another Alternative Pin
Keith Jacquemin18-Mar-04 19:34
memberKeith Jacquemin18-Mar-04 19:34 
GeneralGlobalization Pin
Rudolf Ball17-Aug-03 2:32
memberRudolf Ball17-Aug-03 2:32 
GeneralRe: Globalization Pin
Keith Jacquemin18-Aug-03 6:44
memberKeith Jacquemin18-Aug-03 6:44 
GeneralRe: Globalization Pin
Keith Jacquemin18-Aug-03 15:11
memberKeith Jacquemin18-Aug-03 15:11 
GeneralThank you Pin
dbystrov8-Jul-03 3:11
memberdbystrov8-Jul-03 3:11 
Generalunload the plug-in Pin
khairil6-Apr-03 5:48
memberkhairil6-Apr-03 5:48 
GeneralRe: unload the plug-in Pin
Keith Jacquemin7-Apr-03 8:04
memberKeith Jacquemin7-Apr-03 8:04 
QuestionWriting the config? Pin
JohnGH18-Mar-03 2:47
memberJohnGH18-Mar-03 2:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.1 | Last Updated 16 Dec 2002
Article Copyright 2002 by Keith Jacquemin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid