Click here to Skip to main content
13,899,494 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 10 Feb 2005

Component and ISupportInitialize: A Quick Guide

, 10 Feb 2005
Rate this:
Please Sign up or sign in to vote.
A quick guide about Components and ISupportInitialize intended to help intermediate programmers use the Visual Studio designer more effectively.

Sample Image


Ever wanted to create a control like ErrorProvider that sits in the non-UI portion of the UI designer and does stuff? It's fairly easy. I'll show an example here of how to derive from Component and another helpful interface, ISupportInitialize.


The reason ErrorProvider sits in the non-UI part of the designer is because it is a Component. A Component is the base class for all MarshalByRefObjects in the CLR. Other things that derive from Component are ToolTip, Control, HelpProvider, ImageList, and Menu.

The Component also exposes the site to a container and allows them to communicate. A Component can be placed "in any object that implements the IContainer interface, and can query and get services from its container".

Let's say, I wanted to write a component that would sit in the non-UI part of the designer (does anyone know what the heck that's called?) and after all the initialization is complete at run-time, it would fix the tab ordering automatically. Now, here the tab ordering algorithm is trivial, so let's assume it works. (Thanks to Scott McMaster, who wrote this article and was the inspiration for this article. Sorry about hacking up your TabOrderManager so bad.)

using System;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Specialized;

namespace ComponentTest
    public class TabOrderManager : Component, ISupportInitialize
        public void SetTabOrder()

        // ISupportInitialize members
        public void BeginInit()

        public void EndInit()

Once you slap this on your form (and assign your form to the ContainerControl property), you should notice that something funny has happened in InitializeComponent():

private void InitializeComponent()
    this.tabOrderManager = new ComponentTest.TabOrderManager();

ISupportInitialize adds these things in InitializeComponent automatically. Normally, they are for transacted notification of when batch initialization has started and finished. Now, when the TabOrderManager.EndInit() is called, it sets the tab index of all the components on the form.


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

Software Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Answerthe non-UI part of the designer (does anyone know what the heck that's called?) Pin
khovanskiian3-Dec-08 9:06
memberkhovanskiian3-Dec-08 9:06 
GeneralEditor for ContainerControl Pin
twesterd8-Jun-06 17:12
membertwesterd8-Jun-06 17:12 
QuestionBut how do I get access to the controls? Pin
Anonymous8-Jun-05 8:56
memberAnonymous8-Jun-05 8:56 
AnswerRe: But how do I get access to the controls? Pin
opedog18-Jul-05 7:51
memberopedog18-Jul-05 7:51 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 10 Feb 2005
Article Copyright 2005 by opedog
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid