Link to home
Start Free TrialLog in
Avatar of WickedDancer
WickedDancer

asked on

Derived TabPage (from system.windows.forms.tabpage) - unable to be used in VS.NET Designer. Need advice on how to make it work.

This may not be possible, but I am attempting to derive TabPage and add some functionality to it so that I can use it BOTH in a "Wizard mode" and a "Tabbed Mode".  The Wizard Mode would push events up to the parent TabControl for Next and Prev, and the Tabbed Mode would use the tabs for navigation.  I designed a specific template that I like that I want to use throughout my application.  The problem is that there seems to be no way to add my derived pages to my derived tabcontrol without manually doing a search/replace.  Furthermore, once that is done, and I close and re-open designer, all of my tabs are duplicated and none of the controls on the tabs show up.

Is there some way I can override the tabcontrol designer functionality to do this?  Note: The derived tabs work fine in the context of the application - it's just when I attempt to edit them in designer that things fall apart.

Would sure be nice if MS provided source code for all the controls.

Thanks
Avatar of RomanPetrenko
RomanPetrenko

If you want to override designer for this TabControl.TabPageCollection you have to create the new collection in your control, MYTabControl.MyTabPageCollection, and new property MyTabPages, and inherits from UITypeEditor to create your own TabPages editor.
To support Add MyPage and Remove MyPage in context menu on control, you have to inherits from ControlDesigner.

Do you want to support two types of pages? (TabPage and MyTabPage)
Avatar of WickedDancer

ASKER

I only need to support "MyTabPage", so that should make things simpler. Do you happen to have, or know where I can find, any sample C# code that does this?  Thanks!

The simplest way is to write your own designer, because I don't  think that for TabPages property, you can change type of page created. So you need your own UserTabPages collection...

I wrote a sample for you, it is not complete (Selection in design time work not so good as i wanted), but for understanding of main idea I hope it will be enough.... If you'll have problem with source tell me i'll try to clean up it to make it perfect.
I used following sources to create this control:
http://www.divil.co.uk/net/articles/designers/collectioncontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdesigncontroldesignerclasstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconenhancingdesign-timesupport.asp

==== UserTabControl.cs ====
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace NewTabLib
{
      /// <summary>
      /// Summary description for UserControl1.
      /// </summary>

      [Designer(typeof(UserTabControlDesigner))]//,typeof(System.Windows.Forms.Design.ControlDesigner))]
      public class UserTabControl : System.Windows.Forms.TabControl
      {
            private UserTabPage HighlightedPage;
            [Editor(typeof(UserTabCollectionEditor),typeof(UITypeEditor))]
            public class UserTabPageCollection: CollectionBase //System.Windows.Forms.TabControl.TabPageCollection
            {
                  private UserTabControl _owner;
                  public UserTabPageCollection(UserTabControl owner)//:base(owner)
                  {
                        _owner = owner;
                  }
                  public UserTabPage this[ int index ]  
                  {
                        get  
                        {
                              return( (UserTabPage) List[index] );
                        }
                        set  
                        {
                              List[index] = value;
                        }
                  }

                  public int Add( UserTabPage value )  
                  {
                        _owner.Controls.Add(value);
                        return( List.Add( value ) );
                  }

                  public int IndexOf( UserTabPage value )  
                  {
                        return( List.IndexOf( value ) );
                  }

                  public void Insert( int index, UserTabPage value )  
                  {
                        _owner.Controls.Add(value);
                        List.Insert( index, value );
                  }

                  public void Remove( UserTabPage value )  
                  {
                        List.Remove( value );
                        int idx = _owner.Controls.IndexOf(value);
                        if (idx>=0)
                              _owner.Controls.RemoveAt(idx);
                  }

                  public bool Contains( UserTabPage value )  
                  {
                        // If value is not of type Int16, this will return false.
                        return( List.Contains( value ) );
                  }

                  protected override void OnInsert( int index, Object value )  
                  {
                        if ( value.GetType() != Type.GetType("NewTabLib.UserTabPage") )
                              throw new ArgumentException( "value must be of type NewTabLib.UserTabPage.", "value" );
                  }

                  protected override void OnRemove( int index, Object value )  
                  {
                        if ( value.GetType() != Type.GetType("NewTabLib.UserTabPage") )
                              throw new ArgumentException( "value must be of type NewTabLib.UserTabPage.", "value" );
                  }

                  protected override void OnSet( int index, Object oldValue, Object newValue )  
                  {
                        if ( newValue.GetType() != Type.GetType("NewTabLib.UserTabPage") )
                              throw new ArgumentException( "newValue must be of type NewTabLib.UserTabPage.", "newValue" );
                  }

                  protected override void OnValidate( Object value )  
                  {
                        if ( value.GetType() != Type.GetType("NewTabLib.UserTabPage") )
                              throw new ArgumentException( "value must be of type NewTabLib.UserTabPage." );
                  }
            }
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;
            private UserTabPageCollection _UserTabPages = null;
            public  UserTabPageCollection UserTabPages
            {
                  get
                  {
                        return _UserTabPages;
                  }
            }
            public UserTabControl()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();

                  // TODO: Add any initialization after the InitComponent call

            }
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if( components != null )
                              components.Dispose();
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  _UserTabPages = new UserTabPageCollection(this);
            }
            #endregion

            internal void OnSelectionChanged()
            {
                  UserTabPage newHighlightedPage = null;
                  ISelectionService s = (ISelectionService) GetService(typeof(ISelectionService));

                  // See if the primary selection is one of our buttons
                  foreach (UserTabPage page in UserTabPages)
                  {
                        if (s.PrimarySelection == page)
                        {
                              newHighlightedPage = page;
                              break;
                        }
                  }

                  // Apply if necessary
                  if (newHighlightedPage != HighlightedPage)
                  {
                        HighlightedPage = newHighlightedPage;
                        Invalidate();
                  }
            }


            protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
            {
                  if (DesignMode)
                  {
                        Rectangle wrct;
                        ISelectionService s;
                        bool found = false;
                        ArrayList a;
                        Point pt = new Point(e.X,e.Y);
                        pt = PointToClient(pt);
                        s = (ISelectionService)GetService(typeof(ISelectionService));
                        a = new ArrayList();
                        foreach (UserTabPage page in _UserTabPages)
                        {
                              wrct = page.Bounds;
                              if (wrct.Contains(pt))
                              {
                                    a.Add(page);
                                    SelectedTab = page;
                                    s.SetSelectedComponents(a);
                                    Invalidate();
                                    found = true;
                                    break;
                              }
                        }
                        
                        if (!found)
                        {
                              wrct = Bounds;
                              MessageBox.Show(wrct.ToString()+e.ToString());
                              if (wrct.Contains(e.X,e.Y))
                              {
                                    a.Add(this);
                                    s.SetSelectedComponents(a);
                                    
                              }
                        }
                        Invalidate();
                  }
//                  base.OnMouseDown(e);
            }
      }

      public class UserTabPage: System.Windows.Forms.TabPage
      {
      }
      public class UserTabControlDesigner : System.Windows.Forms.Design.ControlDesigner
      {
            private UserTabControl MyControl;
            protected override void PostFilterProperties(IDictionary properties)
            {
//                  base.PostFilterProperties(properties);
                  properties.Remove("TabPages");
            }

            protected override bool GetHitTest(System.Drawing.Point point)
            {
                  Rectangle wrct;

                  Point pt = MyControl.PointToClient(point);
                  foreach (UserTabPage page in MyControl.UserTabPages)
                  {
                        wrct = page.Bounds;
                        if (wrct.Contains(pt))
                        {
                              MessageBox.Show(pt.ToString() + MyControl.Bounds.ToString());
                              MyControl.SelectedTab = page;
                              MyControl.Invalidate();
                              return true;
                        }
                  }
                  wrct = MyControl.Bounds;
                  if (wrct.Contains(pt))
                  {
                        MessageBox.Show(MyControl.Name);
                        MyControl.Invalidate();
                        return true;
                  }
                  return false;
            }

            
            public UserTabControlDesigner()
            {
            }

            // This method provides an opportunity to perform processing when a designer is initialized.
            // The component parameter is the component that the designer is associated with.
            public override void Initialize(System.ComponentModel.IComponent component)
            {
                  // Always call the base Initialize method in an override of this method.
                  base.Initialize(component);
                  MyControl = (UserTabControl)component;
                  ISelectionService s = (ISelectionService) GetService(typeof(ISelectionService));
                  IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));
                  s.SelectionChanged += new EventHandler(OnSelectionChanged);
                  c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);

            }
            private void OnSelectionChanged(object sender, System.EventArgs e)
            {
                  MyControl.OnSelectionChanged();
            }

            private void OnComponentRemoving(object sender, ComponentEventArgs e)
            {
                  IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));
                  UserTabPage page;
                  IDesignerHost h = (IDesignerHost) GetService(typeof(IDesignerHost));
                  int i;

                  // If the user is removing a button
                  if (e.Component is UserTabPage)
                  {
                        page = (UserTabPage) e.Component;
                        if (MyControl.UserTabPages.Contains(page))
                        {
                              c.OnComponentChanging(MyControl, null);
                              MyControl.UserTabPages.Remove(page);
                              c.OnComponentChanged(MyControl, null, null, null);
                              return;
                        }
                  }

                  // If the user is removing the control itself
                  if (e.Component == MyControl)
                  {
                        for (i = MyControl.UserTabPages.Count - 1; i >= 0; i--)
                        {
                              page = MyControl.UserTabPages[i];
                              c.OnComponentChanging(MyControl, null);
                              MyControl.UserTabPages.Remove(page);
                              h.DestroyComponent(page);
                              c.OnComponentChanged(MyControl, null, null, null);
                        }
                  }
            }

            // This method is invoked when the associated component is double-clicked.
            public override void DoDefaultAction()
            {
                  MessageBox.Show("The event handler for the default action was invoked.");
            }

            // This method provides designer verbs.
            public override System.ComponentModel.Design.DesignerVerbCollection Verbs
            {
                  get
                  {
                        return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Add Tab", new EventHandler(this.AddTab)),
                                                                              new DesignerVerb("Remove Tab", new EventHandler(this.RemoveTab))} );
                  }
            }

            // Event handling method for the example designer verb
            private void AddTab(object sender, EventArgs e)
            {
                  IDesignerHost h = (IDesignerHost)GetService(typeof(IDesignerHost));
                  IComponentChangeService ccs = (IComponentChangeService)GetService(typeof(IComponentChangeService));
                  DesignerTransaction dt = h.CreateTransaction("AddTab");
                  UserTabPage utp = (UserTabPage)h.CreateComponent(typeof(UserTabPage));
                  ccs.OnComponentChanging(MyControl,null);
                  MyControl.UserTabPages.Add(utp);
                  ccs.OnComponentChanged(MyControl,null,null,null);
                  dt.Commit();
            }
            private void RemoveTab(object sender, EventArgs e)
            {
                  IDesignerHost h = (IDesignerHost)GetService(typeof(IDesignerHost));
                  IComponentChangeService ccs = (IComponentChangeService)GetService(typeof(IComponentChangeService));
                  DesignerTransaction dt = h.CreateTransaction("RemoveTab");
                  UserTabPage utp = (UserTabPage)MyControl.SelectedTab;
                  ccs.OnComponentChanging(MyControl,null);
                  MyControl.UserTabPages.Remove(utp);
                  h.DestroyComponent(utp);
                  ccs.OnComponentChanged(MyControl,null,null,null);
                  dt.Commit();
            }
      }
      
      public class UserTabCollectionEditor: UITypeEditor
      {
            [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
            public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
            {
                  return UITypeEditorEditStyle.Modal;
            }

            public override object EditValue(
                  ITypeDescriptorContext context, IServiceProvider provider,
                  object value)
            {
                  if( value.GetType() != typeof(UserTabControl.UserTabPageCollection) )
                        return value;

                  if (provider != null)
                  {
                        IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(
                              typeof(IWindowsFormsEditorService));

                        if (edSvc != null)
                        {
                              UserTabPageCollectionEditor uiEditor =
                                    new UserTabPageCollectionEditor(edSvc, value);
                              edSvc.ShowDialog(uiEditor);
                              value = uiEditor.NewValue;
                        }
                  }

                  return value;
            }

      }
public class UserTabPageCollectionEditor : System.Windows.Forms.Form
      {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public UserTabPageCollectionEditor(IWindowsFormsEditorService svc, object value)
            {
                  NewValue = value;
                  InitializeComponent();
            }
            public object NewValue;
            public UserTabPageCollectionEditor()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  //
                  // UserTabPageCollectionEditor
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(488, 273);
                  this.Name = "UserTabPageCollectionEditor";
                  this.Text = "UserTabPageCollectionEditor";

            }
            #endregion
      }
}

Thanks for the code :)

I tried it out in VS.NET 2003 and got the following error when I attempted a build:

The type or namespace name 'ControlDesigner' does not exist in the class or namespace 'System.Windows.Forms.Design' (are you missing an assembly reference?)

This was on the line:
      <B>public class UserTabControlDesigner : System.Windows.Forms.Design.ControlDesigner</B>
      {
            private UserTabControl MyControl;
...

Have I got an outdated version of .NET or is there some assembly I need to reference for this?

Thanks :)
ControlDesigner defined in system.design.dll you should add it to references of the project
Adding the reference worked to get it to compile.  I then tested it.  As you suggested, the selection does not work at all - it is impossible to select any tab other than the first one either by clicking on the tab or selecting it in the properties editor. Also, the collections editor crashes when I try to use it to manipulate the individual tab page properties.  On the bright side, the tabs don't disappear or duplicate when I close and re-open the forms designer.  

There are probably just a few pieces that are missing to allow for tab page selection and tab collection editing.  It is unfortunate that MS didn't make the base tab code more easily extensible.  Have you managed to get custom tab pages working in any of your projects?

Thanks :)
I will try to make cleanups in sample I gave you to make it work in designer... But, in general, do you understand basic steps?

Do you hide TabPages property to make your control consistent?
ASKER CERTIFIED SOLUTION
Avatar of RomanPetrenko
RomanPetrenko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is REALLY helpful.  Thanks!!!!

Greg
Good luck. :)
Hi,

I had to quickly move to a different project just after I got your solution and just now got back to this project.  Everything appears to work fine EXCEPT that the tabs duplicate themselves when I open and close designer on the form, which was part of the original problem.  I have noticed that the code that Designer auto-generates UserTableControl.Controls.Add statements (one for each tab) in the InitializeComponent() function in the section that initializes the TabControl.  If I manually remove those statements, then everything looks fine - at least until the next time I close and re-open designer on the same form.  Do you know of a way to suppress the code generation that adds the tabs?

Thanks!

Greg
In sample I gave you, I cant reproduce this behavior.
Please describe exactly (step by step) what are you doing and post sample of result code.
Hi,

I have posted the code below that I adapted from the code you posted.  I basically added a few properties and event handlers, but left everything else intact.  To replicate the problem, do the following:

1)  Create a blank Windows Form
2)  Drag a WizardTabControl onto it
3)  Set the Dock attribute to Fill
4)  Either use the "Add" verb, or go into the Tab collection and add 3 tabs
5)  Save everything
6)  Close the designer window for the form
7)  Re-open the designer window for the form
8)  You should notice that
          a)  There are now 6 tabs, each tab being duplicated once
          b)  In the InitializeComponent() code, there are 3 lines adding the tabs to the WizardTabControl
          c)  None of the tabs show any controls
          d)  If the 3 lines of code are deleted, then everything appears correctly


Thanks!

Greg

==============================================
WizardTabControl.cs
==============================================
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace Vortexsoft.UserControls
{
      [Designer(typeof(WizardTabControlDesigner))]
      public class WizardTabControl : System.Windows.Forms.TabControl
      {
            private System.ComponentModel.Container components = null;
            private WizardTabCollection _TabPages = null;
            private System.Drawing.Image tabImage=null;
            private System.EventHandler onApplyButtonClicked;
            private System.EventHandler onOKButtonClicked;
            private System.EventHandler onCancelButtonClicked;
            private System.EventHandler onFinishButtonClicked;
            public bool bWizardMode = true;

            public new WizardTabCollection TabPages
            {
                  get
                  {
                        return _TabPages;
                  }
            }

            public void SetMode(bool bNew)
            {
                  this.bWizardMode = bNew;
                  foreach (WizardTab w in this.TabPages)
                        w.SetMode(bWizardMode);
            }

            [Browsable(true),Description("Image to be used on Wizard tabs"),Category("Appearance")]
            public System.Drawing.Image TabImage
            {
                  get
                  {
                        return this.tabImage;
                  }
                  set
                  {
                        this.tabImage = value;
                  }
            }

            [Browsable(true),Description("Raised when Apply clicked"),Category("Action")]
            public event EventHandler ApplyButtonClicked
            {
                  add
                  {
                        onApplyButtonClicked += value;
                  }
                  remove
                  {
                        onApplyButtonClicked -= value;
                  }
            }

            public virtual void OnApplyButtonClicked(EventArgs e)
            {
                  if (onApplyButtonClicked != null) onApplyButtonClicked.Invoke(this, e);
            }
      
            [Browsable(true),Description("Raised when OK clicked"),Category("Action")]
            public event EventHandler OKButtonClicked
            {
                  add
                  {
                        onOKButtonClicked += value;
                  }
                  remove
                  {
                        onOKButtonClicked -= value;
                  }
            }

            public virtual void OnOKButtonClicked(EventArgs e)
            {
                  if (onOKButtonClicked != null) onOKButtonClicked.Invoke(this, e);
            }
      
            [Browsable(true),Description("Raised when Finish button clicked"),Category("Action")]
            public event EventHandler FinishButtonClicked
            {
                  add
                  {
                        onFinishButtonClicked += value;
                  }
                  remove
                  {
                        onFinishButtonClicked -= value;
                  }
            }

            public virtual void OnFinishButtonClicked(EventArgs e)
            {
                  if (onFinishButtonClicked != null) onFinishButtonClicked.Invoke(this, e);
            }
      
            [Browsable(true),Description("Raised when Cancel clicked"),Category("Action")]
            public event EventHandler CancelButtonClicked
            {
                  add
                  {
                        onCancelButtonClicked += value;
                  }
                  remove
                  {
                        onCancelButtonClicked -= value;
                  }
            }

            public virtual void OnCancelButtonClicked(EventArgs e)
            {
                  if (onCancelButtonClicked != null) onCancelButtonClicked.Invoke(this, e);
            }
      
            public WizardTabControl()
            {
                  InitializeComponent();
            }
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if( components != null )
                              components.Dispose();
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            private void InitializeComponent()
            {
                  _TabPages = new WizardTabCollection(this);
            }
            #endregion
      }

      public class WizardTabControlDesigner : System.Windows.Forms.Design.ParentControlDesigner
      {
            private DesignerVerbCollection verbs = null;
            private DesignerVerb removeVerb = null;
            private bool tabComponentSelected = false;
            private bool disableDrawGrid = false;
            public WizardTabControlDesigner()
            {
                  tabComponentSelected = false;
                  disableDrawGrid = false;
            }
         
            public override bool CanParent(Control control)
            {
                  return (control as WizardTab) !=  null;
            }
         
            protected override bool GetHitTest(Point point)
            {
                  WizardTabControl control = (WizardTabControl) this.Control;
                  if (control == null)
                        return false;
                  if (control.TabPages.Count <= 1)
                        return false;
                  if(this.tabComponentSelected)
                  {
                        bool retval = false;
                        Point pt = control.PointToClient(point);
                        retval = control.ClientRectangle.Contains(pt);
                        return retval;
                  }
                  return false;
            }
            protected override void WndProc(ref System.Windows.Forms.Message m)
            {
                  if (m.Msg == 132) //0x84 - WM_NCHITTEST
                  {
                        base.WndProc(ref m);
                        if (m.Result.ToInt32() == -1)
                        {
                              m.Result = new IntPtr(1);
                              tabComponentSelected = false;
                        }
                        else
                              tabComponentSelected = true;

                        return;
                  }
                  base.WndProc(ref m);
                  return;
            }
            public override void Initialize(System.ComponentModel.IComponent component)
            {
                  base.Initialize(component);
                  ISelectionService ss = (ISelectionService) this.GetService(typeof(ISelectionService));
                  IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
                  if (ss != null)
                        ss.SelectionChanged += new EventHandler(OnSelectionChanged);
                  if (ccs != null)
                  {
                        ccs.ComponentChanging += new ComponentChangingEventHandler(OnComponentChanging);
                        ccs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
                  }
                  ((WizardTabControl)component).SelectedIndexChanged += new EventHandler(OnTabSelectedIndexChanged);
            }
            protected override void Dispose(bool disposing)
            {
                  if (disposing)
                  {
                        ISelectionService ss = (ISelectionService) this.GetService(typeof(ISelectionService));
                        if (ss != null)
                              ss.SelectionChanged -= new EventHandler(OnSelectionChanged);
                        IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(IComponentChangeService));
                        if (ccs != null)
                        {
                              ccs.ComponentChanging -= new ComponentChangingEventHandler(OnComponentChanging);
                              ccs.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged);
                        }
                  }
                  base.Dispose(disposing);
            }

            protected override void PreFilterProperties(IDictionary properties)
            {
                  base.PreFilterProperties(properties);
                  System.Attribute[] attr = new Attribute[0];
                  PropertyDescriptor pd = (PropertyDescriptor) properties["SelectedIndex"];
                  if (pd != null)
                        properties["SelectedIndex"] = TypeDescriptor.CreateProperty(typeof(WizardTabControlDesigner), pd, attr);
            }
            internal static WizardTab GetTabPageOfComponent(object comp)
            {
                  if (comp as Control == null)
                        return null;
                  Control control = (Control) comp;
                  while ((control != null) && ((control as WizardTab) == null))
                        control = control.Parent;
                  return (WizardTab) control;
            }
         
            private void OnComponentChanging(object sender, ComponentChangingEventArgs e)
            {
                  if (e.Component == this.Component && e.Member != null)
                        if (e.Member.Name == "TabPages")
                        {
                              PropertyDescriptor pd = TypeDescriptor.GetProperties(this.Component)["Controls"];
                              this.RaiseComponentChanging(pd);
                        }
            }

            private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
            {
                  if (e.Component == this.Component && e.Member != null)
                        if (e.Member.Name == "TabPages")
                        {
                              PropertyDescriptor pd = TypeDescriptor.GetProperties(this.Component)["Controls"];
                              this.RaiseComponentChanging(pd);
                        }
                  this.CheckVerbStatus();
            }

            private void OnSelectionChanged(object sender, EventArgs e)
            {
                  ISelectionService ss = (ISelectionService) this.GetService(typeof(ISelectionService));
               
                  this.tabComponentSelected = false;
                  if (ss != null)
                  {
                        ICollection coll = ss.GetSelectedComponents();
                        WizardTabControl control = (WizardTabControl) this.Component;
                        IEnumerator iter = coll.GetEnumerator();
                        try
                        {
                              while (iter.MoveNext())
                              {
                                    if (iter.Current == control)
                                          this.tabComponentSelected = true;
                                    WizardTab tp = WizardTabControlDesigner.GetTabPageOfComponent(iter.Current);
                                    if (tp == null || tp.Parent != control)
                                          continue;
                                    this.tabComponentSelected = true;
                                    control.SelectedTab = tp;
                                    break;
                              }
                        }
                        finally
                        {
                              IDisposable dispos = iter as IDisposable;
                              if (dispos != null)
                                    dispos.Dispose();
                        }
                  }
            }

            private void OnTabSelectedIndexChanged(object sender, EventArgs e)
            {
                  ISelectionService ss = (ISelectionService) this.GetService(typeof(ISelectionService));
                  if (ss != null)
                  {
                        ICollection coll = ss.GetSelectedComponents();
                        WizardTabControl control = (WizardTabControl) this.Component;
                        bool found = false;
                        IEnumerator iter = coll.GetEnumerator();
                        try
                        {
                              while (iter.MoveNext())
                              {
                                    WizardTab tp = WizardTabControlDesigner.GetTabPageOfComponent(iter.Current);
                                    if (tp == null || tp.Parent != control || tp != control.SelectedTab)
                                          continue;
                                    found = true;
                                    break;
                              }
                        }
                        finally
                        {
                              IDisposable dispos = iter as IDisposable;
                              if (dispos != null)
                                    dispos.Dispose();
                        }
                        if (!(found))
                        {
                              object[] arr = new Object[1];
                              arr[0] = this.Component;
                              ss.SetSelectedComponents(arr);
                        }
                  }
            }

            protected override void OnPaintAdornments(PaintEventArgs pe)
            {
                  try
                  {
                        this.disableDrawGrid = true;
                        base.OnPaintAdornments(pe);
                  }
                  finally
                  {
                        this.disableDrawGrid = false;
                  }
            }
            protected override bool DrawGrid
            {
                  get
                  {
                        if(disableDrawGrid)
                              return false;
                        return base.DrawGrid;
                  }
            }
            private void CheckVerbStatus()
            {
                  if (this.removeVerb != null)
                        this.removeVerb.Enabled = this.Control.Controls.Count > 0;
            }
     
            public override System.ComponentModel.Design.DesignerVerbCollection Verbs
            {
                  get
                  {
                        if (this.verbs == null)
                        {
                              this.removeVerb = new DesignerVerb("Remove Tab", new EventHandler(OnRemove));
                              this.verbs = new DesignerVerbCollection();
                              this.verbs.Add(new DesignerVerb("Add Tab", new EventHandler(OnAdd)));
                              this.verbs.Add(this.removeVerb);
                        }
                        this.removeVerb.Enabled = this.Control.Controls.Count > 0;
                        return this.verbs;
                  }
            }

            private void OnAdd(object sender, EventArgs eevent)
            {
                  WizardTabControl local0;
                  MemberDescriptor local1;
                  IDesignerHost local2;
                  DesignerTransaction local3;
                  TabPage local5;
                  string local6;
                  PropertyDescriptor local7;

                  local0 = (WizardTabControl) this.Component;
                  local1 = TypeDescriptor.GetProperties(this.Component)["Controls"];
                  local2 = (IDesignerHost) this.GetService(typeof(IDesignerHost));
                  if (local2 != null)
                  {
                        local3 = null;
                        try
                        {
                              try
                              {
                                    local3 = local2.CreateTransaction("WizardTabControlAddTab");
                                    this.RaiseComponentChanging(local1);
                              }
                              catch (CheckoutException local4)
                              {
                                    if (local4 != CheckoutException.Canceled)
                                          throw local4;
                              }
                              local5 = (WizardTab) local2.CreateComponent(typeof(WizardTab));
                              local6 = null;
                              local7 = TypeDescriptor.GetProperties(local5)["Name"];
                              if (local7 != null && local7.PropertyType == typeof(String))
                                    local6 = (String) local7.GetValue(local5);
                              if (local6 != null)
                                    local5.Text = local6;
                              local0.Controls.Add(local5);
                              this.RaiseComponentChanged(local1, null, null);
                        }
                        finally
                        {
                              if (local3 != null)
                                    local3.Commit();
                        }
                  }
            }

            private void OnRemove(object sender, EventArgs eevent)
            {
                  WizardTabControl control = (WizardTabControl) this.Component;
                  if (control == null || control.TabPages.Count == 0)
                        return;
                  MemberDescriptor md = TypeDescriptor.GetProperties(control)["Controls"];
                  WizardTab tp = (WizardTab)control.SelectedTab;
                  IDesignerHost h = (IDesignerHost) this.GetService(typeof(IDesignerHost));
                  if (h != null)
                  {
                        DesignerTransaction trans = null;
                        try
                        {
                              try
                              {
                                    trans = h.CreateTransaction("WizardTabControlRemoveTab");
                                    this.RaiseComponentChanging(md);
                              }
                              catch (CheckoutException ex)
                              {
                                    if (ex != CheckoutException.Canceled)
                                          throw ex;
                              }
                              h.DestroyComponent(tp);
                              this.RaiseComponentChanged(md, null, null);
                        }
                        finally
                        {
                              if (trans != null)
                                    trans.Commit();
                        }
                  }
            }

            private int persistedSelectedIndex = 0;
            private int SelectedIndex
            {
                  get     {return persistedSelectedIndex;     }
                  set     {persistedSelectedIndex = value;}
            }
      }

      public class WizardTabCollection: TabControl.TabPageCollection
      {
            public WizardTabCollection(WizardTabControl owner):base(owner)
            {
            }

            public new WizardTab this[int idx]
            {
                  get     {return (WizardTab)base[idx];}
                  set     {base[idx] = value;}
            }
      }
}

==================================================
WizardTab.cs
==================================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Vortexsoft.UserControls
{
      /// <summary>
      /// Summary description for WizardTab.
      /// </summary>
      public class WizardTab : System.Windows.Forms.TabPage
      {
            private System.Windows.Forms.PictureBox pictureBox1;
            private Vortexsoft.UserControls.HorizontalBar horizontalBar1;
            private bool bIsFinish = false;
            private bool bWizardMode = true;
            private bool bIsFirst = false;
            private System.Windows.Forms.Button btnBack;
            private System.Windows.Forms.Button btnNext;
            private System.Windows.Forms.Button btnCancel;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public WizardTab()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();

                  if (!this.DesignMode && this.Parent != null && this.Parent.TabImage != null)
                  {
                        this.pictureBox1.Image = this.Parent.TabImage;
                  }
            }

            [Description("Indicates whether this tab is the last one.  Applies only in Wizard mode"),Category("Behavior")]
            public bool IsFinish
            {
                  get
                  {
                        return this.bIsFinish;
                  }
                  set
                  {
                        this.bIsFinish = value;
                  }
            }

            [Description("Indicates whether this tab is the first one.  Applies only in Wizard mode"),Category("Behavior")]
            public bool IsFirst
            {
                  get
                  {
                        return this.bIsFirst;
                  }
                  set
                  {
                        this.bIsFirst = value;
                  }
            }

            public void SetMode(bool bNew)
            {
                  this.bWizardMode = bNew;
                  if (bNew)
                  {
                        if (this.bIsFirst)
                        {
                              this.btnBack.Visible = false;
                        }
                        else
                        {
                              this.btnBack.Text = "<< Back";
                              this.btnBack.Visible = true;
                        }
                        if (this.bIsFinish)
                              this.btnNext.Text = "Finish";
                        else
                              this.btnNext.Text = "Next >>";
                  }
                  else
                  {
                        this.btnBack.Text = "Apply";
                        this.btnNext.Text = "OK";
                  }
            }


            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WizardTab));
                  this.pictureBox1 = new System.Windows.Forms.PictureBox();
                  this.horizontalBar1 = new Vortexsoft.UserControls.HorizontalBar();
                  this.btnBack = new System.Windows.Forms.Button();
                  this.btnNext = new System.Windows.Forms.Button();
                  this.btnCancel = new System.Windows.Forms.Button();
                  this.SuspendLayout();
                  //
                  // pictureBox1
                  //
                  this.pictureBox1.AccessibleDescription = resources.GetString("pictureBox1.AccessibleDescription");
                  this.pictureBox1.AccessibleName = resources.GetString("pictureBox1.AccessibleName");
                  this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("pictureBox1.Anchor")));
                  this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
                  this.pictureBox1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("pictureBox1.Dock")));
                  this.pictureBox1.Enabled = ((bool)(resources.GetObject("pictureBox1.Enabled")));
                  this.pictureBox1.Font = ((System.Drawing.Font)(resources.GetObject("pictureBox1.Font")));
                  this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
                  this.pictureBox1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("pictureBox1.ImeMode")));
                  this.pictureBox1.Location = ((System.Drawing.Point)(resources.GetObject("pictureBox1.Location")));
                  this.pictureBox1.Name = "pictureBox1";
                  this.pictureBox1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("pictureBox1.RightToLeft")));
                  this.pictureBox1.Size = ((System.Drawing.Size)(resources.GetObject("pictureBox1.Size")));
                  this.pictureBox1.SizeMode = ((System.Windows.Forms.PictureBoxSizeMode)(resources.GetObject("pictureBox1.SizeMode")));
                  this.pictureBox1.TabIndex = ((int)(resources.GetObject("pictureBox1.TabIndex")));
                  this.pictureBox1.TabStop = false;
                  this.pictureBox1.Text = resources.GetString("pictureBox1.Text");
                  this.pictureBox1.Visible = ((bool)(resources.GetObject("pictureBox1.Visible")));
                  //
                  // horizontalBar1
                  //
                  this.horizontalBar1.AccessibleDescription = resources.GetString("horizontalBar1.AccessibleDescription");
                  this.horizontalBar1.AccessibleName = resources.GetString("horizontalBar1.AccessibleName");
                  this.horizontalBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("horizontalBar1.Anchor")));
                  this.horizontalBar1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("horizontalBar1.BackgroundImage")));
                  this.horizontalBar1.CausesValidation = false;
                  this.horizontalBar1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("horizontalBar1.Dock")));
                  this.horizontalBar1.Enabled = ((bool)(resources.GetObject("horizontalBar1.Enabled")));
                  this.horizontalBar1.Font = ((System.Drawing.Font)(resources.GetObject("horizontalBar1.Font")));
                  this.horizontalBar1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("horizontalBar1.ImeMode")));
                  this.horizontalBar1.Location = ((System.Drawing.Point)(resources.GetObject("horizontalBar1.Location")));
                  this.horizontalBar1.Name = "horizontalBar1";
                  this.horizontalBar1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("horizontalBar1.RightToLeft")));
                  this.horizontalBar1.Size = ((System.Drawing.Size)(resources.GetObject("horizontalBar1.Size")));
                  this.horizontalBar1.TabIndex = ((int)(resources.GetObject("horizontalBar1.TabIndex")));
                  this.horizontalBar1.TabStop = false;
                  this.horizontalBar1.Text = resources.GetString("horizontalBar1.Text");
                  this.horizontalBar1.Visible = ((bool)(resources.GetObject("horizontalBar1.Visible")));
                  //
                  // btnBack
                  //
                  this.btnBack.AccessibleDescription = resources.GetString("btnBack.AccessibleDescription");
                  this.btnBack.AccessibleName = resources.GetString("btnBack.AccessibleName");
                  this.btnBack.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnBack.Anchor")));
                  this.btnBack.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnBack.BackgroundImage")));
                  this.btnBack.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnBack.Dock")));
                  this.btnBack.Enabled = ((bool)(resources.GetObject("btnBack.Enabled")));
                  this.btnBack.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnBack.FlatStyle")));
                  this.btnBack.Font = ((System.Drawing.Font)(resources.GetObject("btnBack.Font")));
                  this.btnBack.Image = ((System.Drawing.Image)(resources.GetObject("btnBack.Image")));
                  this.btnBack.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnBack.ImageAlign")));
                  this.btnBack.ImageIndex = ((int)(resources.GetObject("btnBack.ImageIndex")));
                  this.btnBack.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnBack.ImeMode")));
                  this.btnBack.Location = ((System.Drawing.Point)(resources.GetObject("btnBack.Location")));
                  this.btnBack.Name = "btnBack";
                  this.btnBack.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnBack.RightToLeft")));
                  this.btnBack.Size = ((System.Drawing.Size)(resources.GetObject("btnBack.Size")));
                  this.btnBack.TabIndex = ((int)(resources.GetObject("btnBack.TabIndex")));
                  this.btnBack.Text = resources.GetString("btnBack.Text");
                  this.btnBack.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnBack.TextAlign")));
                  this.btnBack.Visible = ((bool)(resources.GetObject("btnBack.Visible")));
                  this.btnBack.Click += new System.EventHandler(this.btnBack_Click);
                  //
                  // btnNext
                  //
                  this.btnNext.AccessibleDescription = resources.GetString("btnNext.AccessibleDescription");
                  this.btnNext.AccessibleName = resources.GetString("btnNext.AccessibleName");
                  this.btnNext.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnNext.Anchor")));
                  this.btnNext.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnNext.BackgroundImage")));
                  this.btnNext.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnNext.Dock")));
                  this.btnNext.Enabled = ((bool)(resources.GetObject("btnNext.Enabled")));
                  this.btnNext.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnNext.FlatStyle")));
                  this.btnNext.Font = ((System.Drawing.Font)(resources.GetObject("btnNext.Font")));
                  this.btnNext.Image = ((System.Drawing.Image)(resources.GetObject("btnNext.Image")));
                  this.btnNext.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnNext.ImageAlign")));
                  this.btnNext.ImageIndex = ((int)(resources.GetObject("btnNext.ImageIndex")));
                  this.btnNext.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnNext.ImeMode")));
                  this.btnNext.Location = ((System.Drawing.Point)(resources.GetObject("btnNext.Location")));
                  this.btnNext.Name = "btnNext";
                  this.btnNext.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnNext.RightToLeft")));
                  this.btnNext.Size = ((System.Drawing.Size)(resources.GetObject("btnNext.Size")));
                  this.btnNext.TabIndex = ((int)(resources.GetObject("btnNext.TabIndex")));
                  this.btnNext.Text = resources.GetString("btnNext.Text");
                  this.btnNext.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnNext.TextAlign")));
                  this.btnNext.Visible = ((bool)(resources.GetObject("btnNext.Visible")));
                  this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
                  //
                  // btnCancel
                  //
                  this.btnCancel.AccessibleDescription = resources.GetString("btnCancel.AccessibleDescription");
                  this.btnCancel.AccessibleName = resources.GetString("btnCancel.AccessibleName");
                  this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnCancel.Anchor")));
                  this.btnCancel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnCancel.BackgroundImage")));
                  this.btnCancel.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnCancel.Dock")));
                  this.btnCancel.Enabled = ((bool)(resources.GetObject("btnCancel.Enabled")));
                  this.btnCancel.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnCancel.FlatStyle")));
                  this.btnCancel.Font = ((System.Drawing.Font)(resources.GetObject("btnCancel.Font")));
                  this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
                  this.btnCancel.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnCancel.ImageAlign")));
                  this.btnCancel.ImageIndex = ((int)(resources.GetObject("btnCancel.ImageIndex")));
                  this.btnCancel.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnCancel.ImeMode")));
                  this.btnCancel.Location = ((System.Drawing.Point)(resources.GetObject("btnCancel.Location")));
                  this.btnCancel.Name = "btnCancel";
                  this.btnCancel.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnCancel.RightToLeft")));
                  this.btnCancel.Size = ((System.Drawing.Size)(resources.GetObject("btnCancel.Size")));
                  this.btnCancel.TabIndex = ((int)(resources.GetObject("btnCancel.TabIndex")));
                  this.btnCancel.Text = resources.GetString("btnCancel.Text");
                  this.btnCancel.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnCancel.TextAlign")));
                  this.btnCancel.Visible = ((bool)(resources.GetObject("btnCancel.Visible")));
                  this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
                  //
                  // WizardTab
                  //
                  this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
                  this.AccessibleName = resources.GetString("$this.AccessibleName");
                  this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
                  this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
                  this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
                  this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
                  this.Controls.Add(this.btnCancel);
                  this.Controls.Add(this.btnNext);
                  this.Controls.Add(this.btnBack);
                  this.Controls.Add(this.horizontalBar1);
                  this.Controls.Add(this.pictureBox1);
                  this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
                  this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
                  this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
                  this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
                  this.Name = "WizardTab";
                  this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
                  this.Size = ((System.Drawing.Size)(resources.GetObject("$this.Size")));
                  this.ResumeLayout(false);

            }
            #endregion

            public new UserControls.WizardTabControl Parent
            {
                  get
                  {
                        return (UserControls.WizardTabControl) base.Parent;
                  }
                  set
                  {
                        base.Parent = value;
                  }
            }

            private void btnBack_Click(object sender, System.EventArgs e)
            {
                  if (this.bWizardMode)
                        this.Parent.SelectedIndex = this.Parent.SelectedIndex - 1;
                  else
                this.Parent.OnApplyButtonClicked(e);
            }

            private void btnNext_Click(object sender, System.EventArgs e)
            {
                  if (this.bWizardMode)
                  {
                        if (this.bIsFinish)
                              this.Parent.OnFinishButtonClicked(e);
                        else
                              this.Parent.SelectedIndex = this.Parent.SelectedIndex + 1;
                  }
                  else
                  {
                        this.Parent.OnOKButtonClicked(e);
                  }
            }

            private void btnCancel_Click(object sender, System.EventArgs e)
            {
                  this.Parent.OnCancelButtonClicked(e);
            }
      }
}
==================================================================

the problem in your  redefinition of parent property:

public new UserControls.WizardTabControl Parent
          {
               get
               {
                    return (UserControls.WizardTabControl) base.Parent;
               }
               set
               {
                    base.Parent = value;
               }
          }
I think when you set base.Parent to value your control automatically added to parent's controls collection,
when I removed this redefinition and changed in other methods, to ((Vortexsoft.UserControls.WizardTabControl)this.Parent) instead of this.Parent everything works fine
Unless you comment out the HorizontalBar, you will also need this control:

HorizontalBar.cs
================================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Vortexsoft.UserControls
{
      /// <summary>
      /// Summary description for HorizontalBar.
      /// </summary>
      public class HorizontalBar : System.Windows.Forms.Control
      {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;
            private System.Drawing.Pen pDark = null;
            private System.Drawing.Pen pLight = null;
            private System.Drawing.SolidBrush bDark = null;
            private System.Drawing.SolidBrush bLight = null;

            public HorizontalBar()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();
                  Color c = new Color();
                  c = Color.FromArgb(Math.Max(SystemColors.Control.R - 32, 0),
                        Math.Max(SystemColors.Control.G - 32, 0),
                        Math.Max(SystemColors.Control.B - 32, 0));
                  bDark = new SolidBrush(c);
                  c = Color.FromArgb(Math.Min(SystemColors.Control.R + 32, 255),
                        Math.Min(SystemColors.Control.G + 32, 255),
                        Math.Min(SystemColors.Control.B + 32, 255));
                  bLight = new SolidBrush(c);
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if( components != null )
                              components.Dispose();
                        bDark.Dispose();
                        bLight.Dispose();
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  //
                  // HorizontalBar
                  //
                  this.CausesValidation = false;
                  this.Size = new System.Drawing.Size(160, 4);
                  this.TabStop = false;
                  this.Move += new System.EventHandler(this.HorizontalBar_Invalidate);
                  this.SystemColorsChanged += new System.EventHandler(this.HorizontalBar_Invalidate);
                  this.Resize += new System.EventHandler(this.HorizontalBar_Invalidate);
                  this.SizeChanged += new System.EventHandler(this.HorizontalBar_Invalidate);

            }
            #endregion

            protected override void OnPaint(PaintEventArgs pe)
            {
                  // Calling the base class OnPaint
                  try
                  {
                        pDark = new Pen(bDark, this.Height);
                        pLight = new Pen(bLight, this.Height);
                        pe.Graphics.DrawLine(pDark, 0,0,this.Width,0);
                        pe.Graphics.DrawLine(pLight, 0,this.Height,this.Width,this.Height);
//                        pe.Graphics.DrawLine(pDark, 0,this.Height /2,this.Width, this.Height / 2);
//                        pe.Graphics.DrawLine(pLight, 0, this.Height, this.Width, this.Height / 2);
                        pDark.Dispose();
                        pLight.Dispose();
            
                  }
                  catch (Exception ex)
                  {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.StackTrace);
                  }
            }

            private void HorizontalBar_Invalidate(object sender, System.EventArgs e)
            {
                  this.Invalidate();
            }
      }
}
Oops - I sent the last comment before I got your response.  Your suggestion worked! Thanks again for your help and I wish there was a way to provide >500 points.

Greg
I think you can open new question, an post here it's link.
Just put there link to this question for others who would like to know what was solution.