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
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
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.Desi gn;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Desig n;
namespace NewTabLib
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[Designer(typeof(UserTabCo ntrolDesig ner))]//,t ypeof(Syst em.Windows .Forms.Des ign.Contro lDesigner) )]
public class UserTabControl : System.Windows.Forms.TabCo ntrol
{
private UserTabPage HighlightedPage;
[Editor(typeof(UserTabColl ectionEdit or),typeof (UITypeEdi tor))]
public class UserTabPageCollection: CollectionBase //System.Windows.Forms.Tab Control.Ta bPageColle ction
{
private UserTabControl _owner;
public UserTabPageCollection(User TabControl 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(va lue);
if (idx>=0)
_owner.Controls.RemoveAt(i dx);
}
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.Us erTabPage" ) )
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.Us erTabPage" ) )
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.Us erTabPage" ) )
throw new ArgumentException( "newValue must be of type NewTabLib.UserTabPage.", "newValue" );
}
protected override void OnValidate( Object value )
{
if ( value.GetType() != Type.GetType("NewTabLib.Us erTabPage" ) )
throw new ArgumentException( "value must be of type NewTabLib.UserTabPage." );
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer 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(ISelecti onService) );
// 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.Mou seEventArg s 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)GetServ ice(typeof (ISelectio nService)) ;
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.ToStr ing()+e.To String());
if (wrct.Contains(e.X,e.Y))
{
a.Add(this);
s.SetSelectedComponents(a) ;
}
}
Invalidate();
}
// base.OnMouseDown(e);
}
}
public class UserTabPage: System.Windows.Forms.TabPa ge
{
}
public class UserTabControlDesigner : System.Windows.Forms.Desig n.ControlD esigner
{
private UserTabControl MyControl;
protected override void PostFilterProperties(IDict ionary properties)
{
// base.PostFilterProperties( properties );
properties.Remove("TabPage s");
}
protected override bool GetHitTest(System.Drawing. Point point)
{
Rectangle wrct;
Point pt = MyControl.PointToClient(po int);
foreach (UserTabPage page in MyControl.UserTabPages)
{
wrct = page.Bounds;
if (wrct.Contains(pt))
{
MessageBox.Show(pt.ToStrin g() + 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.Componen tModel.ICo mponent component)
{
// Always call the base Initialize method in an override of this method.
base.Initialize(component) ;
MyControl = (UserTabControl)component;
ISelectionService s = (ISelectionService) GetService(typeof(ISelecti onService) );
IComponentChangeService c = (IComponentChangeService)G etService( typeof(ICo mponentCha ngeService ));
s.SelectionChanged += new EventHandler(OnSelectionCh anged);
c.ComponentRemoving += new ComponentEventHandler(OnCo mponentRem oving);
}
private void OnSelectionChanged(object sender, System.EventArgs e)
{
MyControl.OnSelectionChang ed();
}
private void OnComponentRemoving(object sender, ComponentEventArgs e)
{
IComponentChangeService c = (IComponentChangeService)G etService( typeof(ICo mponentCha ngeService ));
UserTabPage page;
IDesignerHost h = (IDesignerHost) GetService(typeof(IDesigne rHost));
int i;
// If the user is removing a button
if (e.Component is UserTabPage)
{
page = (UserTabPage) e.Component;
if (MyControl.UserTabPages.Co ntains(pag e))
{
c.OnComponentChanging(MyCo ntrol, null);
MyControl.UserTabPages.Rem ove(page);
c.OnComponentChanged(MyCon trol, null, null, null);
return;
}
}
// If the user is removing the control itself
if (e.Component == MyControl)
{
for (i = MyControl.UserTabPages.Cou nt - 1; i >= 0; i--)
{
page = MyControl.UserTabPages[i];
c.OnComponentChanging(MyCo ntrol, null);
MyControl.UserTabPages.Rem ove(page);
h.DestroyComponent(page);
c.OnComponentChanged(MyCon trol, 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.Desi gn.Designe rVerbColle ction Verbs
{
get
{
return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Add Tab", new EventHandler(this.AddTab)) ,
new DesignerVerb("Remove Tab", new EventHandler(this.RemoveTa b))} );
}
}
// Event handling method for the example designer verb
private void AddTab(object sender, EventArgs e)
{
IDesignerHost h = (IDesignerHost)GetService( typeof(IDe signerHost ));
IComponentChangeService ccs = (IComponentChangeService)G etService( typeof(ICo mponentCha ngeService ));
DesignerTransaction dt = h.CreateTransaction("AddTa b");
UserTabPage utp = (UserTabPage)h.CreateCompo nent(typeo f(UserTabP age));
ccs.OnComponentChanging(My Control,nu ll);
MyControl.UserTabPages.Add (utp);
ccs.OnComponentChanged(MyC ontrol,nul l,null,nul l);
dt.Commit();
}
private void RemoveTab(object sender, EventArgs e)
{
IDesignerHost h = (IDesignerHost)GetService( typeof(IDe signerHost ));
IComponentChangeService ccs = (IComponentChangeService)G etService( typeof(ICo mponentCha ngeService ));
DesignerTransaction dt = h.CreateTransaction("Remov eTab");
UserTabPage utp = (UserTabPage)MyControl.Sel ectedTab;
ccs.OnComponentChanging(My Control,nu ll);
MyControl.UserTabPages.Rem ove(utp);
h.DestroyComponent(utp);
ccs.OnComponentChanged(MyC ontrol,nul l,null,nul l);
dt.Commit();
}
}
public class UserTabCollectionEditor: UITypeEditor
{
[System.Security.Permissio ns.Permiss ionSet(Sys tem.Securi ty.Permiss ions.Secur ityAction. Demand, Name="FullTrust")]
public override System.Drawing.Design.UITy peEditorEd itStyle GetEditStyle(System.Compon entModel.I TypeDescri ptorContex t context)
{
return UITypeEditorEditStyle.Moda l;
}
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider,
object value)
{
if( value.GetType() != typeof(UserTabControl.User TabPageCol lection) )
return value;
if (provider != null)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorServic e)provider .GetServic e(
typeof(IWindowsFormsEditor Service));
if (edSvc != null)
{
UserTabPageCollectionEdito r uiEditor =
new UserTabPageCollectionEdito r(edSvc, value);
edSvc.ShowDialog(uiEditor) ;
value = uiEditor.NewValue;
}
}
return value;
}
}
public class UserTabPageCollectionEdito r : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer components = null;
public UserTabPageCollectionEdito r(IWindows FormsEdito rService svc, object value)
{
NewValue = value;
InitializeComponent();
}
public object NewValue;
public UserTabPageCollectionEdito r()
{
//
// 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()
{
//
// UserTabPageCollectionEdito r
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 273);
this.Name = "UserTabPageCollectionEdit or";
this.Text = "UserTabPageCollectionEdit or";
}
#endregion
}
}
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.Desi
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Desig
namespace NewTabLib
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[Designer(typeof(UserTabCo
public class UserTabControl : System.Windows.Forms.TabCo
{
private UserTabPage HighlightedPage;
[Editor(typeof(UserTabColl
public class UserTabPageCollection: CollectionBase //System.Windows.Forms.Tab
{
private UserTabControl _owner;
public UserTabPageCollection(User
{
_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(va
if (idx>=0)
_owner.Controls.RemoveAt(i
}
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.Us
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.Us
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.Us
throw new ArgumentException( "newValue must be of type NewTabLib.UserTabPage.", "newValue" );
}
protected override void OnValidate( Object value )
{
if ( value.GetType() != Type.GetType("NewTabLib.Us
throw new ArgumentException( "value must be of type NewTabLib.UserTabPage." );
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
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(ISelecti
// 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
{
if (DesignMode)
{
Rectangle wrct;
ISelectionService s;
bool found = false;
ArrayList a;
Point pt = new Point(e.X,e.Y);
pt = PointToClient(pt);
s = (ISelectionService)GetServ
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.ToStr
if (wrct.Contains(e.X,e.Y))
{
a.Add(this);
s.SetSelectedComponents(a)
}
}
Invalidate();
}
// base.OnMouseDown(e);
}
}
public class UserTabPage: System.Windows.Forms.TabPa
{
}
public class UserTabControlDesigner : System.Windows.Forms.Desig
{
private UserTabControl MyControl;
protected override void PostFilterProperties(IDict
{
// base.PostFilterProperties(
properties.Remove("TabPage
}
protected override bool GetHitTest(System.Drawing.
{
Rectangle wrct;
Point pt = MyControl.PointToClient(po
foreach (UserTabPage page in MyControl.UserTabPages)
{
wrct = page.Bounds;
if (wrct.Contains(pt))
{
MessageBox.Show(pt.ToStrin
MyControl.SelectedTab = page;
MyControl.Invalidate();
return true;
}
}
wrct = MyControl.Bounds;
if (wrct.Contains(pt))
{
MessageBox.Show(MyControl.
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.Componen
{
// Always call the base Initialize method in an override of this method.
base.Initialize(component)
MyControl = (UserTabControl)component;
ISelectionService s = (ISelectionService) GetService(typeof(ISelecti
IComponentChangeService c = (IComponentChangeService)G
s.SelectionChanged += new EventHandler(OnSelectionCh
c.ComponentRemoving += new ComponentEventHandler(OnCo
}
private void OnSelectionChanged(object sender, System.EventArgs e)
{
MyControl.OnSelectionChang
}
private void OnComponentRemoving(object
{
IComponentChangeService c = (IComponentChangeService)G
UserTabPage page;
IDesignerHost h = (IDesignerHost) GetService(typeof(IDesigne
int i;
// If the user is removing a button
if (e.Component is UserTabPage)
{
page = (UserTabPage) e.Component;
if (MyControl.UserTabPages.Co
{
c.OnComponentChanging(MyCo
MyControl.UserTabPages.Rem
c.OnComponentChanged(MyCon
return;
}
}
// If the user is removing the control itself
if (e.Component == MyControl)
{
for (i = MyControl.UserTabPages.Cou
{
page = MyControl.UserTabPages[i];
c.OnComponentChanging(MyCo
MyControl.UserTabPages.Rem
h.DestroyComponent(page);
c.OnComponentChanged(MyCon
}
}
}
// 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.Desi
{
get
{
return new DesignerVerbCollection( new DesignerVerb[] { new DesignerVerb("Add Tab", new EventHandler(this.AddTab))
new DesignerVerb("Remove Tab", new EventHandler(this.RemoveTa
}
}
// Event handling method for the example designer verb
private void AddTab(object sender, EventArgs e)
{
IDesignerHost h = (IDesignerHost)GetService(
IComponentChangeService ccs = (IComponentChangeService)G
DesignerTransaction dt = h.CreateTransaction("AddTa
UserTabPage utp = (UserTabPage)h.CreateCompo
ccs.OnComponentChanging(My
MyControl.UserTabPages.Add
ccs.OnComponentChanged(MyC
dt.Commit();
}
private void RemoveTab(object sender, EventArgs e)
{
IDesignerHost h = (IDesignerHost)GetService(
IComponentChangeService ccs = (IComponentChangeService)G
DesignerTransaction dt = h.CreateTransaction("Remov
UserTabPage utp = (UserTabPage)MyControl.Sel
ccs.OnComponentChanging(My
MyControl.UserTabPages.Rem
h.DestroyComponent(utp);
ccs.OnComponentChanged(MyC
dt.Commit();
}
}
public class UserTabCollectionEditor: UITypeEditor
{
[System.Security.Permissio
public override System.Drawing.Design.UITy
{
return UITypeEditorEditStyle.Moda
}
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider,
object value)
{
if( value.GetType() != typeof(UserTabControl.User
return value;
if (provider != null)
{
IWindowsFormsEditorService
typeof(IWindowsFormsEditor
if (edSvc != null)
{
UserTabPageCollectionEdito
new UserTabPageCollectionEdito
edSvc.ShowDialog(uiEditor)
value = uiEditor.NewValue;
}
}
return value;
}
}
public class UserTabPageCollectionEdito
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
public UserTabPageCollectionEdito
{
NewValue = value;
InitializeComponent();
}
public object NewValue;
public UserTabPageCollectionEdito
{
//
// 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()
{
//
// UserTabPageCollectionEdito
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(488, 273);
this.Name = "UserTabPageCollectionEdit
this.Text = "UserTabPageCollectionEdit
}
#endregion
}
}
ASKER
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.Desi gn' (are you missing an assembly reference?)
This was on the line:
<B>public class UserTabControlDesigner : System.Windows.Forms.Desig n.ControlD esigner</B >
{
private UserTabControl MyControl;
...
Have I got an outdated version of .NET or is there some assembly I need to reference for this?
Thanks :)
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.Desi
This was on the line:
<B>public class UserTabControlDesigner : System.Windows.Forms.Desig
{
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
ASKER
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 :)
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?
Do you hide TabPages property to make your control consistent?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is REALLY helpful. Thanks!!!!
Greg
Greg
Good luck. :)
ASKER
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
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.
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.
Please describe exactly (step by step) what are you doing and post sample of result code.
ASKER
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.Desi gn;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Desig n;
namespace Vortexsoft.UserControls
{
[Designer(typeof(WizardTab ControlDes igner))]
public class WizardTabControl : System.Windows.Forms.TabCo ntrol
{
private System.ComponentModel.Cont ainer 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),Descripti on("Image to be used on Wizard tabs"),Category("Appearanc e")]
public System.Drawing.Image TabImage
{
get
{
return this.tabImage;
}
set
{
this.tabImage = value;
}
}
[Browsable(true),Descripti on("Raised when Apply clicked"),Category("Action ")]
public event EventHandler ApplyButtonClicked
{
add
{
onApplyButtonClicked += value;
}
remove
{
onApplyButtonClicked -= value;
}
}
public virtual void OnApplyButtonClicked(Event Args e)
{
if (onApplyButtonClicked != null) onApplyButtonClicked.Invok e(this, e);
}
[Browsable(true),Descripti on("Raised when OK clicked"),Category("Action ")]
public event EventHandler OKButtonClicked
{
add
{
onOKButtonClicked += value;
}
remove
{
onOKButtonClicked -= value;
}
}
public virtual void OnOKButtonClicked(EventArg s e)
{
if (onOKButtonClicked != null) onOKButtonClicked.Invoke(t his, e);
}
[Browsable(true),Descripti on("Raised when Finish button clicked"),Category("Action ")]
public event EventHandler FinishButtonClicked
{
add
{
onFinishButtonClicked += value;
}
remove
{
onFinishButtonClicked -= value;
}
}
public virtual void OnFinishButtonClicked(Even tArgs e)
{
if (onFinishButtonClicked != null) onFinishButtonClicked.Invo ke(this, e);
}
[Browsable(true),Descripti on("Raised when Cancel clicked"),Category("Action ")]
public event EventHandler CancelButtonClicked
{
add
{
onCancelButtonClicked += value;
}
remove
{
onCancelButtonClicked -= value;
}
}
public virtual void OnCancelButtonClicked(Even tArgs e)
{
if (onCancelButtonClicked != null) onCancelButtonClicked.Invo ke(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.Desig n.ParentCo ntrolDesig ner
{
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.tabComponentSelect ed)
{
bool retval = false;
Point pt = control.PointToClient(poin t);
retval = control.ClientRectangle.Co ntains(pt) ;
return retval;
}
return false;
}
protected override void WndProc(ref System.Windows.Forms.Messa ge 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.Componen tModel.ICo mponent component)
{
base.Initialize(component) ;
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe lectionSer vice));
IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(ICo mponentCha ngeService ));
if (ss != null)
ss.SelectionChanged += new EventHandler(OnSelectionCh anged);
if (ccs != null)
{
ccs.ComponentChanging += new ComponentChangingEventHand ler(OnComp onentChang ing);
ccs.ComponentChanged += new ComponentChangedEventHandl er(OnCompo nentChange d);
}
((WizardTabControl)compone nt).Select edIndexCha nged += new EventHandler(OnTabSelected IndexChang ed);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe lectionSer vice));
if (ss != null)
ss.SelectionChanged -= new EventHandler(OnSelectionCh anged);
IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(ICo mponentCha ngeService ));
if (ccs != null)
{
ccs.ComponentChanging -= new ComponentChangingEventHand ler(OnComp onentChang ing);
ccs.ComponentChanged -= new ComponentChangedEventHandl er(OnCompo nentChange d);
}
}
base.Dispose(disposing);
}
protected override void PreFilterProperties(IDicti onary properties)
{
base.PreFilterProperties(p roperties) ;
System.Attribute[] attr = new Attribute[0];
PropertyDescriptor pd = (PropertyDescriptor) properties["SelectedIndex" ];
if (pd != null)
properties["SelectedIndex" ] = TypeDescriptor.CreatePrope rty(typeof (WizardTab ControlDes igner), pd, attr);
}
internal static WizardTab GetTabPageOfComponent(obje ct 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.GetProperti es(this.Co mponent)[" Controls"] ;
this.RaiseComponentChangin g(pd);
}
}
private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
if (e.Component == this.Component && e.Member != null)
if (e.Member.Name == "TabPages")
{
PropertyDescriptor pd = TypeDescriptor.GetProperti es(this.Co mponent)[" Controls"] ;
this.RaiseComponentChangin g(pd);
}
this.CheckVerbStatus();
}
private void OnSelectionChanged(object sender, EventArgs e)
{
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe lectionSer vice));
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.G etTabPageO fComponent (iter.Curr ent);
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(ISe lectionSer vice));
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.G etTabPageO fComponent (iter.Curr ent);
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(a rr);
}
}
}
protected override void OnPaintAdornments(PaintEve ntArgs 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.Coun t > 0;
}
public override System.ComponentModel.Desi gn.Designe rVerbColle ction 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.remove Verb);
}
this.removeVerb.Enabled = this.Control.Controls.Coun t > 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.GetProperti es(this.Co mponent)[" Controls"] ;
local2 = (IDesignerHost) this.GetService(typeof(IDe signerHost ));
if (local2 != null)
{
local3 = null;
try
{
try
{
local3 = local2.CreateTransaction(" WizardTabC ontrolAddT ab");
this.RaiseComponentChangin g(local1);
}
catch (CheckoutException local4)
{
if (local4 != CheckoutException.Canceled )
throw local4;
}
local5 = (WizardTab) local2.CreateComponent(typ eof(Wizard Tab));
local6 = null;
local7 = TypeDescriptor.GetProperti es(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.GetProperti es(control )["Control s"];
WizardTab tp = (WizardTab)control.Selecte dTab;
IDesignerHost h = (IDesignerHost) this.GetService(typeof(IDe signerHost ));
if (h != null)
{
DesignerTransaction trans = null;
try
{
try
{
trans = h.CreateTransaction("Wizar dTabContro lRemoveTab ");
this.RaiseComponentChangin g(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.TabPageCollecti on
{
public WizardTabCollection(Wizard TabControl 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.TabPa ge
{
private System.Windows.Forms.Pictu reBox pictureBox1;
private Vortexsoft.UserControls.Ho rizontalBa r horizontalBar1;
private bool bIsFinish = false;
private bool bWizardMode = true;
private bool bIsFirst = false;
private System.Windows.Forms.Butto n btnBack;
private System.Windows.Forms.Butto n btnNext;
private System.Windows.Forms.Butto n btnCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer 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.ResourceM anager resources = new System.Resources.ResourceM anager(typ eof(Wizard Tab));
this.pictureBox1 = new System.Windows.Forms.Pictu reBox();
this.horizontalBar1 = new Vortexsoft.UserControls.Ho rizontalBa r();
this.btnBack = new System.Windows.Forms.Butto n();
this.btnNext = new System.Windows.Forms.Butto n();
this.btnCancel = new System.Windows.Forms.Butto n();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Accessibl eDescripti on = resources.GetString("pictu reBox1.Acc essibleDes cription") ;
this.pictureBox1.Accessibl eName = resources.GetString("pictu reBox1.Acc essibleNam e");
this.pictureBox1.Anchor = ((System.Windows.Forms.Anc horStyles) (resources .GetObject ("pictureB ox1.Anchor ")));
this.pictureBox1.Backgroun dImage = ((System.Drawing.Image)(re sources.Ge tObject("p ictureBox1 .Backgroun dImage"))) ;
this.pictureBox1.Dock = ((System.Windows.Forms.Doc kStyle)(re sources.Ge tObject("p ictureBox1 .Dock")));
this.pictureBox1.Enabled = ((bool)(resources.GetObjec t("picture Box1.Enabl ed")));
this.pictureBox1.Font = ((System.Drawing.Font)(res ources.Get Object("pi ctureBox1. Font")));
this.pictureBox1.Image = ((System.Drawing.Image)(re sources.Ge tObject("p ictureBox1 .Image"))) ;
this.pictureBox1.ImeMode = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("pic tureBox1.I meMode"))) ;
this.pictureBox1.Location = ((System.Drawing.Point)(re sources.Ge tObject("p ictureBox1 .Location" )));
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.RightToLe ft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "pictureBo x1.RightTo Left")));
this.pictureBox1.Size = ((System.Drawing.Size)(res ources.Get Object("pi ctureBox1. Size")));
this.pictureBox1.SizeMode = ((System.Windows.Forms.Pic tureBoxSiz eMode)(res ources.Get Object("pi ctureBox1. SizeMode") ));
this.pictureBox1.TabIndex = ((int)(resources.GetObject ("pictureB ox1.TabInd ex")));
this.pictureBox1.TabStop = false;
this.pictureBox1.Text = resources.GetString("pictu reBox1.Tex t");
this.pictureBox1.Visible = ((bool)(resources.GetObjec t("picture Box1.Visib le")));
//
// horizontalBar1
//
this.horizontalBar1.Access ibleDescri ption = resources.GetString("horiz ontalBar1. Accessible Descriptio n");
this.horizontalBar1.Access ibleName = resources.GetString("horiz ontalBar1. Accessible Name");
this.horizontalBar1.Anchor = ((System.Windows.Forms.Anc horStyles) (resources .GetObject ("horizont alBar1.Anc hor")));
this.horizontalBar1.Backgr oundImage = ((System.Drawing.Image)(re sources.Ge tObject("h orizontalB ar1.Backgr oundImage" )));
this.horizontalBar1.Causes Validation = false;
this.horizontalBar1.Dock = ((System.Windows.Forms.Doc kStyle)(re sources.Ge tObject("h orizontalB ar1.Dock") ));
this.horizontalBar1.Enable d = ((bool)(resources.GetObjec t("horizon talBar1.En abled")));
this.horizontalBar1.Font = ((System.Drawing.Font)(res ources.Get Object("ho rizontalBa r1.Font")) );
this.horizontalBar1.ImeMod e = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("hor izontalBar 1.ImeMode" )));
this.horizontalBar1.Locati on = ((System.Drawing.Point)(re sources.Ge tObject("h orizontalB ar1.Locati on")));
this.horizontalBar1.Name = "horizontalBar1";
this.horizontalBar1.RightT oLeft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "horizonta lBar1.Righ tToLeft")) );
this.horizontalBar1.Size = ((System.Drawing.Size)(res ources.Get Object("ho rizontalBa r1.Size")) );
this.horizontalBar1.TabInd ex = ((int)(resources.GetObject ("horizont alBar1.Tab Index")));
this.horizontalBar1.TabSto p = false;
this.horizontalBar1.Text = resources.GetString("horiz ontalBar1. Text");
this.horizontalBar1.Visibl e = ((bool)(resources.GetObjec t("horizon talBar1.Vi sible")));
//
// btnBack
//
this.btnBack.AccessibleDes cription = resources.GetString("btnBa ck.Accessi bleDescrip tion");
this.btnBack.AccessibleNam e = resources.GetString("btnBa ck.Accessi bleName");
this.btnBack.Anchor = ((System.Windows.Forms.Anc horStyles) (resources .GetObject ("btnBack. Anchor"))) ;
this.btnBack.BackgroundIma ge = ((System.Drawing.Image)(re sources.Ge tObject("b tnBack.Bac kgroundIma ge")));
this.btnBack.Dock = ((System.Windows.Forms.Doc kStyle)(re sources.Ge tObject("b tnBack.Doc k")));
this.btnBack.Enabled = ((bool)(resources.GetObjec t("btnBack .Enabled") ));
this.btnBack.FlatStyle = ((System.Windows.Forms.Fla tStyle)(re sources.Ge tObject("b tnBack.Fla tStyle"))) ;
this.btnBack.Font = ((System.Drawing.Font)(res ources.Get Object("bt nBack.Font ")));
this.btnBack.Image = ((System.Drawing.Image)(re sources.Ge tObject("b tnBack.Ima ge")));
this.btnBack.ImageAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnBack.Im ageAlign") ));
this.btnBack.ImageIndex = ((int)(resources.GetObject ("btnBack. ImageIndex ")));
this.btnBack.ImeMode = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("btn Back.ImeMo de")));
this.btnBack.Location = ((System.Drawing.Point)(re sources.Ge tObject("b tnBack.Loc ation")));
this.btnBack.Name = "btnBack";
this.btnBack.RightToLeft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "btnBack.R ightToLeft ")));
this.btnBack.Size = ((System.Drawing.Size)(res ources.Get Object("bt nBack.Size ")));
this.btnBack.TabIndex = ((int)(resources.GetObject ("btnBack. TabIndex") ));
this.btnBack.Text = resources.GetString("btnBa ck.Text");
this.btnBack.TextAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnBack.Te xtAlign")) );
this.btnBack.Visible = ((bool)(resources.GetObjec t("btnBack .Visible") ));
this.btnBack.Click += new System.EventHandler(this.b tnBack_Cli ck);
//
// btnNext
//
this.btnNext.AccessibleDes cription = resources.GetString("btnNe xt.Accessi bleDescrip tion");
this.btnNext.AccessibleNam e = resources.GetString("btnNe xt.Accessi bleName");
this.btnNext.Anchor = ((System.Windows.Forms.Anc horStyles) (resources .GetObject ("btnNext. Anchor"))) ;
this.btnNext.BackgroundIma ge = ((System.Drawing.Image)(re sources.Ge tObject("b tnNext.Bac kgroundIma ge")));
this.btnNext.Dock = ((System.Windows.Forms.Doc kStyle)(re sources.Ge tObject("b tnNext.Doc k")));
this.btnNext.Enabled = ((bool)(resources.GetObjec t("btnNext .Enabled") ));
this.btnNext.FlatStyle = ((System.Windows.Forms.Fla tStyle)(re sources.Ge tObject("b tnNext.Fla tStyle"))) ;
this.btnNext.Font = ((System.Drawing.Font)(res ources.Get Object("bt nNext.Font ")));
this.btnNext.Image = ((System.Drawing.Image)(re sources.Ge tObject("b tnNext.Ima ge")));
this.btnNext.ImageAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnNext.Im ageAlign") ));
this.btnNext.ImageIndex = ((int)(resources.GetObject ("btnNext. ImageIndex ")));
this.btnNext.ImeMode = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("btn Next.ImeMo de")));
this.btnNext.Location = ((System.Drawing.Point)(re sources.Ge tObject("b tnNext.Loc ation")));
this.btnNext.Name = "btnNext";
this.btnNext.RightToLeft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "btnNext.R ightToLeft ")));
this.btnNext.Size = ((System.Drawing.Size)(res ources.Get Object("bt nNext.Size ")));
this.btnNext.TabIndex = ((int)(resources.GetObject ("btnNext. TabIndex") ));
this.btnNext.Text = resources.GetString("btnNe xt.Text");
this.btnNext.TextAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnNext.Te xtAlign")) );
this.btnNext.Visible = ((bool)(resources.GetObjec t("btnNext .Visible") ));
this.btnNext.Click += new System.EventHandler(this.b tnNext_Cli ck);
//
// btnCancel
//
this.btnCancel.AccessibleD escription = resources.GetString("btnCa ncel.Acces sibleDescr iption");
this.btnCancel.AccessibleN ame = resources.GetString("btnCa ncel.Acces sibleName" );
this.btnCancel.Anchor = ((System.Windows.Forms.Anc horStyles) (resources .GetObject ("btnCance l.Anchor") ));
this.btnCancel.BackgroundI mage = ((System.Drawing.Image)(re sources.Ge tObject("b tnCancel.B ackgroundI mage")));
this.btnCancel.Dock = ((System.Windows.Forms.Doc kStyle)(re sources.Ge tObject("b tnCancel.D ock")));
this.btnCancel.Enabled = ((bool)(resources.GetObjec t("btnCanc el.Enabled ")));
this.btnCancel.FlatStyle = ((System.Windows.Forms.Fla tStyle)(re sources.Ge tObject("b tnCancel.F latStyle") ));
this.btnCancel.Font = ((System.Drawing.Font)(res ources.Get Object("bt nCancel.Fo nt")));
this.btnCancel.Image = ((System.Drawing.Image)(re sources.Ge tObject("b tnCancel.I mage")));
this.btnCancel.ImageAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnCancel. ImageAlign ")));
this.btnCancel.ImageIndex = ((int)(resources.GetObject ("btnCance l.ImageInd ex")));
this.btnCancel.ImeMode = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("btn Cancel.Ime Mode")));
this.btnCancel.Location = ((System.Drawing.Point)(re sources.Ge tObject("b tnCancel.L ocation")) );
this.btnCancel.Name = "btnCancel";
this.btnCancel.RightToLeft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "btnCancel .RightToLe ft")));
this.btnCancel.Size = ((System.Drawing.Size)(res ources.Get Object("bt nCancel.Si ze")));
this.btnCancel.TabIndex = ((int)(resources.GetObject ("btnCance l.TabIndex ")));
this.btnCancel.Text = resources.GetString("btnCa ncel.Text" );
this.btnCancel.TextAlign = ((System.Drawing.ContentAl ignment)(r esources.G etObject(" btnCancel. TextAlign" )));
this.btnCancel.Visible = ((bool)(resources.GetObjec t("btnCanc el.Visible ")));
this.btnCancel.Click += new System.EventHandler(this.b tnCancel_C lick);
//
// WizardTab
//
this.AccessibleDescription = resources.GetString("$this .Accessibl eDescripti on");
this.AccessibleName = resources.GetString("$this .Accessibl eName");
this.AutoScroll = ((bool)(resources.GetObjec t("$this.A utoScroll" )));
this.AutoScrollMargin = ((System.Drawing.Size)(res ources.Get Object("$t his.AutoSc rollMargin ")));
this.AutoScrollMinSize = ((System.Drawing.Size)(res ources.Get Object("$t his.AutoSc rollMinSiz e")));
this.BackgroundImage = ((System.Drawing.Image)(re sources.Ge tObject("$ this.Backg roundImage ")));
this.Controls.Add(this.btn Cancel);
this.Controls.Add(this.btn Next);
this.Controls.Add(this.btn Back);
this.Controls.Add(this.hor izontalBar 1);
this.Controls.Add(this.pic tureBox1);
this.Enabled = ((bool)(resources.GetObjec t("$this.E nabled"))) ;
this.Font = ((System.Drawing.Font)(res ources.Get Object("$t his.Font") ));
this.ImeMode = ((System.Windows.Forms.Ime Mode)(reso urces.GetO bject("$th is.ImeMode ")));
this.Location = ((System.Drawing.Point)(re sources.Ge tObject("$ this.Locat ion")));
this.Name = "WizardTab";
this.RightToLeft = ((System.Windows.Forms.Rig htToLeft)( resources. GetObject( "$this.Rig htToLeft") ));
this.Size = ((System.Drawing.Size)(res ources.Get Object("$t his.Size") ));
this.ResumeLayout(false);
}
#endregion
public new UserControls.WizardTabCont rol Parent
{
get
{
return (UserControls.WizardTabCon trol) 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.OnApplyButtonC licked(e);
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if (this.bWizardMode)
{
if (this.bIsFinish)
this.Parent.OnFinishButton Clicked(e) ;
else
this.Parent.SelectedIndex = this.Parent.SelectedIndex + 1;
}
else
{
this.Parent.OnOKButtonClic ked(e);
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Parent.OnCancelButton Clicked(e) ;
}
}
}
========================== ========== ========== ========== ==========
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.Desi
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
using System.Windows.Forms.Desig
namespace Vortexsoft.UserControls
{
[Designer(typeof(WizardTab
public class WizardTabControl : System.Windows.Forms.TabCo
{
private System.ComponentModel.Cont
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),Descripti
public System.Drawing.Image TabImage
{
get
{
return this.tabImage;
}
set
{
this.tabImage = value;
}
}
[Browsable(true),Descripti
public event EventHandler ApplyButtonClicked
{
add
{
onApplyButtonClicked += value;
}
remove
{
onApplyButtonClicked -= value;
}
}
public virtual void OnApplyButtonClicked(Event
{
if (onApplyButtonClicked != null) onApplyButtonClicked.Invok
}
[Browsable(true),Descripti
public event EventHandler OKButtonClicked
{
add
{
onOKButtonClicked += value;
}
remove
{
onOKButtonClicked -= value;
}
}
public virtual void OnOKButtonClicked(EventArg
{
if (onOKButtonClicked != null) onOKButtonClicked.Invoke(t
}
[Browsable(true),Descripti
public event EventHandler FinishButtonClicked
{
add
{
onFinishButtonClicked += value;
}
remove
{
onFinishButtonClicked -= value;
}
}
public virtual void OnFinishButtonClicked(Even
{
if (onFinishButtonClicked != null) onFinishButtonClicked.Invo
}
[Browsable(true),Descripti
public event EventHandler CancelButtonClicked
{
add
{
onCancelButtonClicked += value;
}
remove
{
onCancelButtonClicked -= value;
}
}
public virtual void OnCancelButtonClicked(Even
{
if (onCancelButtonClicked != null) onCancelButtonClicked.Invo
}
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.Desig
{
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.tabComponentSelect
{
bool retval = false;
Point pt = control.PointToClient(poin
retval = control.ClientRectangle.Co
return retval;
}
return false;
}
protected override void WndProc(ref System.Windows.Forms.Messa
{
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.Componen
{
base.Initialize(component)
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe
IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(ICo
if (ss != null)
ss.SelectionChanged += new EventHandler(OnSelectionCh
if (ccs != null)
{
ccs.ComponentChanging += new ComponentChangingEventHand
ccs.ComponentChanged += new ComponentChangedEventHandl
}
((WizardTabControl)compone
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe
if (ss != null)
ss.SelectionChanged -= new EventHandler(OnSelectionCh
IComponentChangeService ccs = (IComponentChangeService) this.GetService(typeof(ICo
if (ccs != null)
{
ccs.ComponentChanging -= new ComponentChangingEventHand
ccs.ComponentChanged -= new ComponentChangedEventHandl
}
}
base.Dispose(disposing);
}
protected override void PreFilterProperties(IDicti
{
base.PreFilterProperties(p
System.Attribute[] attr = new Attribute[0];
PropertyDescriptor pd = (PropertyDescriptor) properties["SelectedIndex"
if (pd != null)
properties["SelectedIndex"
}
internal static WizardTab GetTabPageOfComponent(obje
{
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
{
if (e.Component == this.Component && e.Member != null)
if (e.Member.Name == "TabPages")
{
PropertyDescriptor pd = TypeDescriptor.GetProperti
this.RaiseComponentChangin
}
}
private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
if (e.Component == this.Component && e.Member != null)
if (e.Member.Name == "TabPages")
{
PropertyDescriptor pd = TypeDescriptor.GetProperti
this.RaiseComponentChangin
}
this.CheckVerbStatus();
}
private void OnSelectionChanged(object sender, EventArgs e)
{
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe
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.G
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(
{
ISelectionService ss = (ISelectionService) this.GetService(typeof(ISe
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.G
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(a
}
}
}
protected override void OnPaintAdornments(PaintEve
{
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.Coun
}
public override System.ComponentModel.Desi
{
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.remove
}
this.removeVerb.Enabled = this.Control.Controls.Coun
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.GetProperti
local2 = (IDesignerHost) this.GetService(typeof(IDe
if (local2 != null)
{
local3 = null;
try
{
try
{
local3 = local2.CreateTransaction("
this.RaiseComponentChangin
}
catch (CheckoutException local4)
{
if (local4 != CheckoutException.Canceled
throw local4;
}
local5 = (WizardTab) local2.CreateComponent(typ
local6 = null;
local7 = TypeDescriptor.GetProperti
if (local7 != null && local7.PropertyType == typeof(String))
local6 = (String) local7.GetValue(local5);
if (local6 != null)
local5.Text = local6;
local0.Controls.Add(local5
this.RaiseComponentChanged
}
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.GetProperti
WizardTab tp = (WizardTab)control.Selecte
IDesignerHost h = (IDesignerHost) this.GetService(typeof(IDe
if (h != null)
{
DesignerTransaction trans = null;
try
{
try
{
trans = h.CreateTransaction("Wizar
this.RaiseComponentChangin
}
catch (CheckoutException ex)
{
if (ex != CheckoutException.Canceled
throw ex;
}
h.DestroyComponent(tp);
this.RaiseComponentChanged
}
finally
{
if (trans != null)
trans.Commit();
}
}
}
private int persistedSelectedIndex = 0;
private int SelectedIndex
{
get {return persistedSelectedIndex; }
set {persistedSelectedIndex = value;}
}
}
public class WizardTabCollection: TabControl.TabPageCollecti
{
public WizardTabCollection(Wizard
{
}
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.TabPa
{
private System.Windows.Forms.Pictu
private Vortexsoft.UserControls.Ho
private bool bIsFinish = false;
private bool bWizardMode = true;
private bool bIsFirst = false;
private System.Windows.Forms.Butto
private System.Windows.Forms.Butto
private System.Windows.Forms.Butto
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
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.ResourceM
this.pictureBox1 = new System.Windows.Forms.Pictu
this.horizontalBar1 = new Vortexsoft.UserControls.Ho
this.btnBack = new System.Windows.Forms.Butto
this.btnNext = new System.Windows.Forms.Butto
this.btnCancel = new System.Windows.Forms.Butto
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Accessibl
this.pictureBox1.Accessibl
this.pictureBox1.Anchor = ((System.Windows.Forms.Anc
this.pictureBox1.Backgroun
this.pictureBox1.Dock = ((System.Windows.Forms.Doc
this.pictureBox1.Enabled = ((bool)(resources.GetObjec
this.pictureBox1.Font = ((System.Drawing.Font)(res
this.pictureBox1.Image = ((System.Drawing.Image)(re
this.pictureBox1.ImeMode = ((System.Windows.Forms.Ime
this.pictureBox1.Location = ((System.Drawing.Point)(re
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.RightToLe
this.pictureBox1.Size = ((System.Drawing.Size)(res
this.pictureBox1.SizeMode = ((System.Windows.Forms.Pic
this.pictureBox1.TabIndex = ((int)(resources.GetObject
this.pictureBox1.TabStop = false;
this.pictureBox1.Text = resources.GetString("pictu
this.pictureBox1.Visible = ((bool)(resources.GetObjec
//
// horizontalBar1
//
this.horizontalBar1.Access
this.horizontalBar1.Access
this.horizontalBar1.Anchor
this.horizontalBar1.Backgr
this.horizontalBar1.Causes
this.horizontalBar1.Dock = ((System.Windows.Forms.Doc
this.horizontalBar1.Enable
this.horizontalBar1.Font = ((System.Drawing.Font)(res
this.horizontalBar1.ImeMod
this.horizontalBar1.Locati
this.horizontalBar1.Name = "horizontalBar1";
this.horizontalBar1.RightT
this.horizontalBar1.Size = ((System.Drawing.Size)(res
this.horizontalBar1.TabInd
this.horizontalBar1.TabSto
this.horizontalBar1.Text = resources.GetString("horiz
this.horizontalBar1.Visibl
//
// btnBack
//
this.btnBack.AccessibleDes
this.btnBack.AccessibleNam
this.btnBack.Anchor = ((System.Windows.Forms.Anc
this.btnBack.BackgroundIma
this.btnBack.Dock = ((System.Windows.Forms.Doc
this.btnBack.Enabled = ((bool)(resources.GetObjec
this.btnBack.FlatStyle = ((System.Windows.Forms.Fla
this.btnBack.Font = ((System.Drawing.Font)(res
this.btnBack.Image = ((System.Drawing.Image)(re
this.btnBack.ImageAlign = ((System.Drawing.ContentAl
this.btnBack.ImageIndex = ((int)(resources.GetObject
this.btnBack.ImeMode = ((System.Windows.Forms.Ime
this.btnBack.Location = ((System.Drawing.Point)(re
this.btnBack.Name = "btnBack";
this.btnBack.RightToLeft = ((System.Windows.Forms.Rig
this.btnBack.Size = ((System.Drawing.Size)(res
this.btnBack.TabIndex = ((int)(resources.GetObject
this.btnBack.Text = resources.GetString("btnBa
this.btnBack.TextAlign = ((System.Drawing.ContentAl
this.btnBack.Visible = ((bool)(resources.GetObjec
this.btnBack.Click += new System.EventHandler(this.b
//
// btnNext
//
this.btnNext.AccessibleDes
this.btnNext.AccessibleNam
this.btnNext.Anchor = ((System.Windows.Forms.Anc
this.btnNext.BackgroundIma
this.btnNext.Dock = ((System.Windows.Forms.Doc
this.btnNext.Enabled = ((bool)(resources.GetObjec
this.btnNext.FlatStyle = ((System.Windows.Forms.Fla
this.btnNext.Font = ((System.Drawing.Font)(res
this.btnNext.Image = ((System.Drawing.Image)(re
this.btnNext.ImageAlign = ((System.Drawing.ContentAl
this.btnNext.ImageIndex = ((int)(resources.GetObject
this.btnNext.ImeMode = ((System.Windows.Forms.Ime
this.btnNext.Location = ((System.Drawing.Point)(re
this.btnNext.Name = "btnNext";
this.btnNext.RightToLeft = ((System.Windows.Forms.Rig
this.btnNext.Size = ((System.Drawing.Size)(res
this.btnNext.TabIndex = ((int)(resources.GetObject
this.btnNext.Text = resources.GetString("btnNe
this.btnNext.TextAlign = ((System.Drawing.ContentAl
this.btnNext.Visible = ((bool)(resources.GetObjec
this.btnNext.Click += new System.EventHandler(this.b
//
// btnCancel
//
this.btnCancel.AccessibleD
this.btnCancel.AccessibleN
this.btnCancel.Anchor = ((System.Windows.Forms.Anc
this.btnCancel.BackgroundI
this.btnCancel.Dock = ((System.Windows.Forms.Doc
this.btnCancel.Enabled = ((bool)(resources.GetObjec
this.btnCancel.FlatStyle = ((System.Windows.Forms.Fla
this.btnCancel.Font = ((System.Drawing.Font)(res
this.btnCancel.Image = ((System.Drawing.Image)(re
this.btnCancel.ImageAlign = ((System.Drawing.ContentAl
this.btnCancel.ImageIndex = ((int)(resources.GetObject
this.btnCancel.ImeMode = ((System.Windows.Forms.Ime
this.btnCancel.Location = ((System.Drawing.Point)(re
this.btnCancel.Name = "btnCancel";
this.btnCancel.RightToLeft
this.btnCancel.Size = ((System.Drawing.Size)(res
this.btnCancel.TabIndex = ((int)(resources.GetObject
this.btnCancel.Text = resources.GetString("btnCa
this.btnCancel.TextAlign = ((System.Drawing.ContentAl
this.btnCancel.Visible = ((bool)(resources.GetObjec
this.btnCancel.Click += new System.EventHandler(this.b
//
// WizardTab
//
this.AccessibleDescription
this.AccessibleName = resources.GetString("$this
this.AutoScroll = ((bool)(resources.GetObjec
this.AutoScrollMargin = ((System.Drawing.Size)(res
this.AutoScrollMinSize = ((System.Drawing.Size)(res
this.BackgroundImage = ((System.Drawing.Image)(re
this.Controls.Add(this.btn
this.Controls.Add(this.btn
this.Controls.Add(this.btn
this.Controls.Add(this.hor
this.Controls.Add(this.pic
this.Enabled = ((bool)(resources.GetObjec
this.Font = ((System.Drawing.Font)(res
this.ImeMode = ((System.Windows.Forms.Ime
this.Location = ((System.Drawing.Point)(re
this.Name = "WizardTab";
this.RightToLeft = ((System.Windows.Forms.Rig
this.Size = ((System.Drawing.Size)(res
this.ResumeLayout(false);
}
#endregion
public new UserControls.WizardTabCont
{
get
{
return (UserControls.WizardTabCon
}
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.OnApplyButtonC
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if (this.bWizardMode)
{
if (this.bIsFinish)
this.Parent.OnFinishButton
else
this.Parent.SelectedIndex = this.Parent.SelectedIndex + 1;
}
else
{
this.Parent.OnOKButtonClic
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Parent.OnCancelButton
}
}
}
==========================
the problem in your redefinition of parent property:
public new UserControls.WizardTabCont rol Parent
{
get
{
return (UserControls.WizardTabCon trol) 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. WizardTabC ontrol)thi s.Parent) instead of this.Parent everything works fine
public new UserControls.WizardTabCont
{
get
{
return (UserControls.WizardTabCon
}
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.
ASKER
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.Contr ol
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer 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(Sy stemColors .Control.R - 32, 0),
Math.Max(SystemColors.Cont rol.G - 32, 0),
Math.Max(SystemColors.Cont rol.B - 32, 0));
bDark = new SolidBrush(c);
c = Color.FromArgb(Math.Min(Sy stemColors .Control.R + 32, 255),
Math.Min(SystemColors.Cont rol.G + 32, 255),
Math.Min(SystemColors.Cont rol.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.H orizontalB ar_Invalid ate);
this.SystemColorsChanged += new System.EventHandler(this.H orizontalB ar_Invalid ate);
this.Resize += new System.EventHandler(this.H orizontalB ar_Invalid ate);
this.SizeChanged += new System.EventHandler(this.H orizontalB ar_Invalid ate);
}
#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(pLigh t, 0,this.Height,this.Width,t his.Height );
// pe.Graphics.DrawLine(pDark , 0,this.Height /2,this.Width, this.Height / 2);
// pe.Graphics.DrawLine(pLigh t, 0, this.Height, this.Width, this.Height / 2);
pDark.Dispose();
pLight.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Messa ge);
Console.WriteLine(ex.Stack Trace);
}
}
private void HorizontalBar_Invalidate(o bject sender, System.EventArgs e)
{
this.Invalidate();
}
}
}
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.Contr
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
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(Sy
Math.Max(SystemColors.Cont
Math.Max(SystemColors.Cont
bDark = new SolidBrush(c);
c = Color.FromArgb(Math.Min(Sy
Math.Min(SystemColors.Cont
Math.Min(SystemColors.Cont
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.H
this.SystemColorsChanged += new System.EventHandler(this.H
this.Resize += new System.EventHandler(this.H
this.SizeChanged += new System.EventHandler(this.H
}
#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
pe.Graphics.DrawLine(pLigh
// pe.Graphics.DrawLine(pDark
// pe.Graphics.DrawLine(pLigh
pDark.Dispose();
pLight.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Messa
Console.WriteLine(ex.Stack
}
}
private void HorizontalBar_Invalidate(o
{
this.Invalidate();
}
}
}
ASKER
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
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.
Just put there link to this question for others who would like to know what was solution.
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)