473,699 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding custom TabPages at design time

Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would
contain tab pages of my own classes, I know you can achieve this with ListView columns so it should be doable, thanks
Dec 13 '06 #1
11 18125
Either add the ToolBoxItemAttr ibute to your custom TabPage Class so that you
can drag and drop it from the toolbox, or Inherit from TabControl and give
it a custom TabPageCollecti on.

You'll find an example of the latter on my TabControls tips page
http://www.dotnetrix.co.uk/tabcontrols.html

For VS2005 you'll need to add a ScrollableContr olDesigner to the custom
TabPage or it will misbehave in the IDE.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:eG******** *****@TK2MSFTNG P02.phx.gbl...
Hi All, does anyone know how to add TabPages of ones own classes at design
time ? ideally when adding a new TabControl it would contain tab pages of
my own classes, I know you can achieve this with ListView columns so it
should be doable, thanks

Dec 13 '06 #2
Mick Doherty wrote:
Either add the ToolBoxItemAttr ibute to your custom TabPage Class so that you
can drag and drop it from the toolbox, or Inherit from TabControl and give
it a custom TabPageCollecti on.

You'll find an example of the latter on my TabControls tips page
http://www.dotnetrix.co.uk/tabcontrols.html

For VS2005 you'll need to add a ScrollableContr olDesigner to the custom
TabPage or it will misbehave in the IDE.
Thanks Mick, It (your sample tabcontrol with custom tabpages) looks very impressive but which parts do I need to have my custom
pages added by default (i.e. when adding a tabcontrol in the IDE) and when adding subsequent pages in the designer ? thanks a lot
Dec 14 '06 #3
You need most of the code.

The actual TabControl and Custom TabPage class are not too extensive. In
order to modify the DesignerVerbs (Add Tab, Remove Tab) you must supply a
custom TabControlDesig ner, and in VS2005 you must supply a custom
TabPageDesigner .

The TabPageDesigner is very simple as it only needs to be assigned as a
ScrollableContr olDesigner, but the TabControlDesig ner is quite complex as
the control needs to be navigated at DesignTime as well as at Runtime and
the System.Windows. Forms.Design.Ta bControlDesigne r cannot be Inherited.

I've created an example in it's most basic form, but there's still a fair
amount of code here.

The System.Windows. Forms.TabPage will misbehave in the VS2005 IDE, and so I
have created a basic TabPage class with no special function. It is simply an
Inherited System.Windows. Forms.TabPage which uses a ScrollControlDe signer.
All of your Custom TabPages should be inherited from this class. For the
purpose of the example, I have created a RandomColorTabP age, just to show
implementation.

The Add verb/SmartTag will add a basic TabPage.
The CollectionEdito r will add a basic TabPage if you simply click on the Add
button, but the button has a dropdown which will allow you to choose a
RandomColorTabP age to add instead.
To change the TabPage types that will show in the dropdown list, simply
modify the MyTabPageCollec tionEditor's CreateNewItemTy pes() method to return
the Type Array that you want.
To Change the TabPage type added via the Add Tab verb, simply modify the
type in the TabControlDesig ner's OnAddPage() method.
At runtime you may add instances of System.Windows. Forms.TabPage without
penalty.

Here's the code: (note that you will need to add a reference to
System.Design.d ll)
\\\
using System;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Drawing. Design;

namespace Dotnetrix.Examp les
{
[Designer(typeof (MyTabControlDe signer))]
public class MyTabControl : System.Windows. Forms.TabContro l
{
[Editor(typeof(M yTabPageCollect ionEditor), typeof(UITypeEd itor))]
public new TabPageCollecti on TabPages
{
get
{
return base.TabPages;
}
}

internal class MyTabPageCollec tionEditor : CollectionEdito r
{
protected override CollectionEdito r.CollectionFor m
CreateCollectio nForm()
{
CollectionForm baseForm = base.CreateColl ectionForm();
baseForm.Text = "MyTabPage Collection Editor";
return baseForm;
}

public MyTabPageCollec tionEditor(Syst em.Type type)
: base(type)
{
}
protected override Type CreateCollectio nItemType()
{
return typeof(RandomCo lorTabPage);
}
protected override Type[] CreateNewItemTy pes()
{
return new Type[] { typeof(TabPage) ,
typeof(RandomCo lorTabPage) };
}

}

}

[Designer(typeof (System.Windows .Forms.Design.S crollableContro lDesigner))]
public class TabPage : System.Windows. Forms.TabPage
{
public TabPage()
: base()
{
}
}

public class RandomColorTabP age : TabPage
{
public RandomColorTabP age()
: base()
{
this.BackColor = RandomColor();
}

private static Random ColorRandomizer = new Random();

private System.Drawing. Color RandomColor()
{
return System.Drawing. Color.FromArgb( ColorRandomizer .Next(256),
ColorRandomizer .Next(256),
ColorRandomizer .Next(256));
}
}
internal class MyTabControlDes igner :
System.Windows. Forms.Design.Pa rentControlDesi gner
{

#region Private Instance Variables

private DesignerVerbCol lection m_verbs = new
DesignerVerbCol lection();
private IDesignerHost m_DesignerHost;
private ISelectionServi ce m_SelectionServ ice;

#endregion

public MyTabControlDes igner()
: base()
{
DesignerVerb verb1 = new DesignerVerb("A dd Tab", new
EventHandler(On AddPage));
DesignerVerb verb2 = new DesignerVerb("R emove Tab", new
EventHandler(On RemovePage));
m_verbs.AddRang e(new DesignerVerb[] { verb1, verb2 });
}

#region Properties

public override DesignerVerbCol lection Verbs
{
get
{
if (m_verbs.Count == 2)
{
MyTabControl MyControl = (MyTabControl)C ontrol;
if (MyControl.TabC ount 0)
{
m_verbs[1].Enabled = true;
}
else
{
m_verbs[1].Enabled = false;
}
}
return m_verbs;
}
}

public IDesignerHost DesignerHost
{
get
{
if (m_DesignerHost == null)
m_DesignerHost =
(IDesignerHost) (GetService(typ eof(IDesignerHo st)));

return m_DesignerHost;
}
}

public ISelectionServi ce SelectionServic e
{
get
{
if (m_SelectionSer vice == null)
m_SelectionServ ice =
(ISelectionServ ice)(this.GetSe rvice(typeof(IS electionService )));
return m_SelectionServ ice;
}
}

#endregion

void OnAddPage(Objec t sender, EventArgs e)
{
MyTabControl ParentControl = (MyTabControl)C ontrol;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs =
ParentControl.C ontrols;

RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

System.Windows. Forms.TabPage P =
(System.Windows .Forms.TabPage) (DesignerHost.C reateComponent( typeof(TabPage) ));
P.Text = P.Name;
ParentControl.T abPages.Add(P);

RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"],
oldTabs, ParentControl.T abPages);
ParentControl.S electedTab = P;

SetVerbs();

}

void OnRemovePage(Ob ject sender, EventArgs e)
{
MyTabControl ParentControl = (MyTabControl)C ontrol;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs =
ParentControl.C ontrols;

if (ParentControl. SelectedIndex < 0) return;

RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

DesignerHost.De stroyComponent( ParentControl.T abPages[ParentControl.S electedIndex]);

RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"],
oldTabs, ParentControl.T abPages);

SelectionServic e.SetSelectedCo mponents(new IComponent[] {
ParentControl }, SelectionTypes. Auto);

SetVerbs();

}

private void SetVerbs()
{
MyTabControl ParentControl = (MyTabControl)C ontrol;

switch (ParentControl. TabPages.Count)
{
case 0:
Verbs[1].Enabled = false;
break;
default:
Verbs[1].Enabled = true;
break;
}
}

private const int WM_NCHITTEST = 0x84;

private const int HTTRANSPARENT = -1;
private const int HTCLIENT = 1;

protected override void WndProc(ref System.Windows. Forms.Message m)
{
base.WndProc(re f m);
if (m.Msg == WM_NCHITTEST)
{
//select tabcontrol when Tabcontrol clicked outside of
TabItem.
if (m.Result.ToInt 32() == HTTRANSPARENT)
m.Result = (IntPtr)HTCLIEN T;
}

}

private enum TabControlHitTe st
{
TCHT_NOWHERE = 1,
TCHT_ONITEMICON = 2,
TCHT_ONITEMLABE L = 4,
TCHT_ONITEM = TCHT_ONITEMICON | TCHT_ONITEMLABE L
}

private const int TCM_HITTEST = 0x130D;

private struct TCHITTESTINFO
{
public System.Drawing. Point pt;
public TabControlHitTe st flags;
}

protected override bool GetHitTest(Syst em.Drawing.Poin t point)
{
if (this.Selection Service.Primary Selection == this.Control)
{
TCHITTESTINFO hti = new TCHITTESTINFO() ;

hti.pt = this.Control.Po intToClient(poi nt);
hti.flags = 0;

System.Windows. Forms.Message m = new
System.Windows. Forms.Message() ;
m.HWnd = this.Control.Ha ndle;
m.Msg = TCM_HITTEST;

IntPtr lparam =
System.Runtime. InteropServices .Marshal.AllocH Global(System.R untime.InteropS ervices.Marshal .SizeOf(hti));
System.Runtime. InteropServices .Marshal.Struct ureToPtr(hti,
lparam, false);
m.LParam = lparam;

base.WndProc(re f m);
System.Runtime. InteropServices .Marshal.FreeHG lobal(lparam);

if (m.Result.ToInt 32() != -1)
return hti.flags != TabControlHitTe st.TCHT_NOWHERE ;

}

return false;
}

protected override void
OnPaintAdornmen ts(System.Windo ws.Forms.PaintE ventArgs pe)
{
//Don't want DrawGrid dots.
}

//Fix the AllSizable selectionrule on DockStyle.Fill
public override System.Windows. Forms.Design.Se lectionRules
SelectionRules
{
get
{
if (Control.Dock == System.Windows. Forms.DockStyle .Fill)
return
System.Windows. Forms.Design.Se lectionRules.Vi sible;
return base.SelectionR ules;
}
}

}

}
///

HTH

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:ez******** ******@TK2MSFTN GP03.phx.gbl...
Mick Doherty wrote:
>Either add the ToolBoxItemAttr ibute to your custom TabPage Class so that
you can drag and drop it from the toolbox, or Inherit from TabControl and
give it a custom TabPageCollecti on.

You'll find an example of the latter on my TabControls tips page
http://www.dotnetrix.co.uk/tabcontrols.html

For VS2005 you'll need to add a ScrollableContr olDesigner to the custom
TabPage or it will misbehave in the IDE.

Thanks Mick, It (your sample tabcontrol with custom tabpages) looks very
impressive but which parts do I need to have my custom pages added by
default (i.e. when adding a tabcontrol in the IDE) and when adding
subsequent pages in the designer ? thanks a lot

Dec 14 '06 #4
Mick Doherty wrote:
You need most of the code.

The actual TabControl and Custom TabPage class are not too extensive. In
order to modify the DesignerVerbs (Add Tab, Remove Tab) you must supply a
custom TabControlDesig ner, and in VS2005 you must supply a custom
TabPageDesigner .

The TabPageDesigner is very simple as it only needs to be assigned as a
ScrollableContr olDesigner, but the TabControlDesig ner is quite complex as
the control needs to be navigated at DesignTime as well as at Runtime and
the System.Windows. Forms.Design.Ta bControlDesigne r cannot be Inherited.

I've created an example in it's most basic form, but there's still a fair
amount of code here.

The System.Windows. Forms.TabPage will misbehave in the VS2005 IDE, and so I
have created a basic TabPage class with no special function. It is simply an
Inherited System.Windows. Forms.TabPage which uses a ScrollControlDe signer.
All of your Custom TabPages should be inherited from this class. For the
purpose of the example, I have created a RandomColorTabP age, just to show
implementation.

The Add verb/SmartTag will add a basic TabPage.
The CollectionEdito r will add a basic TabPage if you simply click on the Add
button, but the button has a dropdown which will allow you to choose a
RandomColorTabP age to add instead.
To change the TabPage types that will show in the dropdown list, simply
modify the MyTabPageCollec tionEditor's CreateNewItemTy pes() method to return
the Type Array that you want.
To Change the TabPage type added via the Add Tab verb, simply modify the
type in the TabControlDesig ner's OnAddPage() method.
At runtime you may add instances of System.Windows. Forms.TabPage without
penalty.

Here's the code: (note that you will need to add a reference to
System.Design.d ll)
\\\
using System;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Drawing. Design;

namespace Dotnetrix.Examp les
{
[Designer(typeof (MyTabControlDe signer))]
public class MyTabControl : System.Windows. Forms.TabContro l
{
[Editor(typeof(M yTabPageCollect ionEditor), typeof(UITypeEd itor))]
public new TabPageCollecti on TabPages
{
get
{
return base.TabPages;
}
}

internal class MyTabPageCollec tionEditor : CollectionEdito r
{
protected override CollectionEdito r.CollectionFor m
CreateCollectio nForm()
{
CollectionForm baseForm = base.CreateColl ectionForm();
baseForm.Text = "MyTabPage Collection Editor";
return baseForm;
}

public MyTabPageCollec tionEditor(Syst em.Type type)
: base(type)
{
}
protected override Type CreateCollectio nItemType()
{
return typeof(RandomCo lorTabPage);
}
protected override Type[] CreateNewItemTy pes()
{
return new Type[] { typeof(TabPage) ,
typeof(RandomCo lorTabPage) };
}

}

}

[Designer(typeof (System.Windows .Forms.Design.S crollableContro lDesigner))]
public class TabPage : System.Windows. Forms.TabPage
{
public TabPage()
: base()
{
}
}

public class RandomColorTabP age : TabPage
{
public RandomColorTabP age()
: base()
{
this.BackColor = RandomColor();
}

private static Random ColorRandomizer = new Random();

private System.Drawing. Color RandomColor()
{
return System.Drawing. Color.FromArgb( ColorRandomizer .Next(256),
ColorRandomizer .Next(256),
ColorRandomizer .Next(256));
}
}
internal class MyTabControlDes igner :
System.Windows. Forms.Design.Pa rentControlDesi gner
{

#region Private Instance Variables

private DesignerVerbCol lection m_verbs = new
DesignerVerbCol lection();
private IDesignerHost m_DesignerHost;
private ISelectionServi ce m_SelectionServ ice;

#endregion

public MyTabControlDes igner()
: base()
{
DesignerVerb verb1 = new DesignerVerb("A dd Tab", new
EventHandler(On AddPage));
DesignerVerb verb2 = new DesignerVerb("R emove Tab", new
EventHandler(On RemovePage));
m_verbs.AddRang e(new DesignerVerb[] { verb1, verb2 });
}

#region Properties

public override DesignerVerbCol lection Verbs
{
get
{
if (m_verbs.Count == 2)
{
MyTabControl MyControl = (MyTabControl)C ontrol;
if (MyControl.TabC ount 0)
{
m_verbs[1].Enabled = true;
}
else
{
m_verbs[1].Enabled = false;
}
}
return m_verbs;
}
}

public IDesignerHost DesignerHost
{
get
{
if (m_DesignerHost == null)
m_DesignerHost =
(IDesignerHost) (GetService(typ eof(IDesignerHo st)));

return m_DesignerHost;
}
}

public ISelectionServi ce SelectionServic e
{
get
{
if (m_SelectionSer vice == null)
m_SelectionServ ice =
(ISelectionServ ice)(this.GetSe rvice(typeof(IS electionService )));
return m_SelectionServ ice;
}
}

#endregion

void OnAddPage(Objec t sender, EventArgs e)
{
MyTabControl ParentControl = (MyTabControl)C ontrol;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs =
ParentControl.C ontrols;

RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

System.Windows. Forms.TabPage P =
(System.Windows .Forms.TabPage) (DesignerHost.C reateComponent( typeof(TabPage) ));
P.Text = P.Name;
ParentControl.T abPages.Add(P);

RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"],
oldTabs, ParentControl.T abPages);
ParentControl.S electedTab = P;

SetVerbs();

}

void OnRemovePage(Ob ject sender, EventArgs e)
{
MyTabControl ParentControl = (MyTabControl)C ontrol;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs =
ParentControl.C ontrols;

if (ParentControl. SelectedIndex < 0) return;

RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

DesignerHost.De stroyComponent( ParentControl.T abPages[ParentControl.S electedIndex]);

RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"],
oldTabs, ParentControl.T abPages);

SelectionServic e.SetSelectedCo mponents(new IComponent[] {
ParentControl }, SelectionTypes. Auto);

SetVerbs();

}

private void SetVerbs()
{
MyTabControl ParentControl = (MyTabControl)C ontrol;

switch (ParentControl. TabPages.Count)
{
case 0:
Verbs[1].Enabled = false;
break;
default:
Verbs[1].Enabled = true;
break;
}
}

private const int WM_NCHITTEST = 0x84;

private const int HTTRANSPARENT = -1;
private const int HTCLIENT = 1;

protected override void WndProc(ref System.Windows. Forms.Message m)
{
base.WndProc(re f m);
if (m.Msg == WM_NCHITTEST)
{
//select tabcontrol when Tabcontrol clicked outside of
TabItem.
if (m.Result.ToInt 32() == HTTRANSPARENT)
m.Result = (IntPtr)HTCLIEN T;
}

}

private enum TabControlHitTe st
{
TCHT_NOWHERE = 1,
TCHT_ONITEMICON = 2,
TCHT_ONITEMLABE L = 4,
TCHT_ONITEM = TCHT_ONITEMICON | TCHT_ONITEMLABE L
}

private const int TCM_HITTEST = 0x130D;

private struct TCHITTESTINFO
{
public System.Drawing. Point pt;
public TabControlHitTe st flags;
}

protected override bool GetHitTest(Syst em.Drawing.Poin t point)
{
if (this.Selection Service.Primary Selection == this.Control)
{
TCHITTESTINFO hti = new TCHITTESTINFO() ;

hti.pt = this.Control.Po intToClient(poi nt);
hti.flags = 0;

System.Windows. Forms.Message m = new
System.Windows. Forms.Message() ;
m.HWnd = this.Control.Ha ndle;
m.Msg = TCM_HITTEST;

IntPtr lparam =
System.Runtime. InteropServices .Marshal.AllocH Global(System.R untime.InteropS ervices.Marshal .SizeOf(hti));
System.Runtime. InteropServices .Marshal.Struct ureToPtr(hti,
lparam, false);
m.LParam = lparam;

base.WndProc(re f m);
System.Runtime. InteropServices .Marshal.FreeHG lobal(lparam);

if (m.Result.ToInt 32() != -1)
return hti.flags != TabControlHitTe st.TCHT_NOWHERE ;

}

return false;
}

protected override void
OnPaintAdornmen ts(System.Windo ws.Forms.PaintE ventArgs pe)
{
//Don't want DrawGrid dots.
}

//Fix the AllSizable selectionrule on DockStyle.Fill
public override System.Windows. Forms.Design.Se lectionRules
SelectionRules
{
get
{
if (Control.Dock == System.Windows. Forms.DockStyle .Fill)
return
System.Windows. Forms.Design.Se lectionRules.Vi sible;
return base.SelectionR ules;
}
}

}

}
///

HTH
Thanks Mick , where did you learn all this ?, is there a book I can buy which explains how to create custom designers ?, once again
thanks very much for your comprehensive solution
Dec 15 '06 #5
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:uq******** ******@TK2MSFTN GP03.phx.gbl...
Mick Doherty wrote:
>>
<--SNIP-->
>>
Thanks Mick , where did you learn all this ?, is there a book I can buy
which explains how to create custom designers ?
The only .Net book that I have ever used was '.Net Windows Forms Custom
Controls'. ISBN: 0-672-32333-8
I couldn't say how that compares with other books, but it only briefly goes
into Designers. I really only used the book to help convert my existing
VBClassic coding skills to .Net.

If I can't find an answer or a hint within Google Groups then I generally
get direction via the help files or the MSDN Library and then just play
until it works. This is the most satisfying way to do it, but it can also be
quite stressful.

I probably spend far too much time on the PC programming, and not enough
down the pub ;-)

thanks very much for your comprehensive solution
You're welcome.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
Dec 15 '06 #6
I think there is a market for a book on the designer / class attributes
- you could write it in the pub ! , thanks again
Mick Doherty wrote:
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:uq******** ******@TK2MSFTN GP03.phx.gbl...
>>Mick Doherty wrote:
<--SNIP-->
>>Thanks Mick , where did you learn all this ?, is there a book I can buy
which explains how to create custom designers ?


The only .Net book that I have ever used was '.Net Windows Forms Custom
Controls'. ISBN: 0-672-32333-8
I couldn't say how that compares with other books, but it only briefly goes
into Designers. I really only used the book to help convert my existing
VBClassic coding skills to .Net.

If I can't find an answer or a hint within Google Groups then I generally
get direction via the help files or the MSDN Library and then just play
until it works. This is the most satisfying way to do it, but it can also be
quite stressful.

I probably spend far too much time on the PC programming, and not enough
down the pub ;-)
>>thanks very much for your comprehensive solution


You're welcome.
Dec 16 '06 #7
Mick Doherty wrote:
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:uq******** ******@TK2MSFTN GP03.phx.gbl...
>Mick Doherty wrote:
<--SNIP-->
>Thanks Mick , where did you learn all this ?, is there a book I can buy
which explains how to create custom designers ?

The only .Net book that I have ever used was '.Net Windows Forms Custom
Controls'. ISBN: 0-672-32333-8
I couldn't say how that compares with other books, but it only briefly goes
into Designers. I really only used the book to help convert my existing
VBClassic coding skills to .Net.

If I can't find an answer or a hint within Google Groups then I generally
get direction via the help files or the MSDN Library and then just play
until it works. This is the most satisfying way to do it, but it can also be
quite stressful.

I probably spend far too much time on the PC programming, and not enough
down the pub ;-)

>thanks very much for your comprehensive solution

You're welcome.
Hello Mick, don't know if you're still following this thread but here goes, I have my class working very well now in the IDE, what I
would like to be able to do is control the "Name" it is given at design time - it's not a huge issue but would save some time
renaming, no matter what I try my TabPages are always "Named" e.g. PJKBaseTabPage1 etc..., my OnAddPage() is as shown below, the
"Text" property takes the new value but the "Name" doesn't , any ideas ?, thanks

void OnAddPage(Objec t sender, EventArgs e)
{
PJKBaseTabContr ol ParentControl = (PJKBaseTabCont rol)Control;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs = ParentControl.C ontrols;

RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

PJKBaseTabPage P = (PJKBaseTabPage )(DesignerHost. CreateComponent (typeof(PJKBase TabPage)));

int NewPageNumber = ParentControl.T abCount + 1;
string PageName = "Page " + NewPageNumber.T oString();
P.Text = PageName;
ParentControl.T abPages.Add(P);
RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"], oldTabs, ParentControl.T abPages);
ParentControl.T abPages[NewPageNumber - 1].Name = PageName.Remove (PageName.LastI ndexOf(" "), 1);
ParentControl.S electedTab = P;
SetVerbs();
}
Dec 19 '06 #8
You were almost there ;-)

The IDesignerHost.C reateComponent( ) method has an overload that takes a Name
value.

int NewPageNumber = ParentControl.T abCount + 1;
PJKBaseTabPage P =
(PJKBaseTabPage )(DesignerHost. CreateComponent (typeof(PJKBase TabPage), "Page"
+ NewPageNumber.T oString()));
P.Text = PageName;
ParentControl.T abPages.Add(P);

However, this will only result in those tabpages added via the 'Add Tab'
verb/smart tag to be custom named and of course, if you remove a tabpage,
the naming algorithm will fail.

I haven't actually tried to modify the Name of the control/component being
added before, so I don't have the correct answer off the top of my head. I
probably won't have a chance to look into it this side of Christmas now, but
if you've not found the answer by the time I do get a chance to look, I'll
post it here.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:uL******** *****@TK2MSFTNG P06.phx.gbl...
Mick Doherty wrote:
>"Pete Kane" <pj**********@u ku.co.ukwrote in message
news:uq******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Mick Doherty wrote:
<--SNIP-->
>>Thanks Mick , where did you learn all this ?, is there a book I can buy
which explains how to create custom designers ?

The only .Net book that I have ever used was '.Net Windows Forms Custom
Controls'. ISBN: 0-672-32333-8
I couldn't say how that compares with other books, but it only briefly
goes into Designers. I really only used the book to help convert my
existing VBClassic coding skills to .Net.

If I can't find an answer or a hint within Google Groups then I generally
get direction via the help files or the MSDN Library and then just play
until it works. This is the most satisfying way to do it, but it can also
be quite stressful.

I probably spend far too much time on the PC programming, and not enough
down the pub ;-)

>>thanks very much for your comprehensive solution

You're welcome.
Hello Mick, don't know if you're still following this thread but here
goes, I have my class working very well now in the IDE, what I would like
to be able to do is control the "Name" it is given at design time - it's
not a huge issue but would save some time renaming, no matter what I try
my TabPages are always "Named" e.g. PJKBaseTabPage1 etc..., my OnAddPage()
is as shown below, the "Text" property takes the new value but the "Name"
doesn't , any ideas ?, thanks

void OnAddPage(Objec t sender, EventArgs e)
{
PJKBaseTabContr ol ParentControl = (PJKBaseTabCont rol)Control;
System.Windows. Forms.Control.C ontrolCollectio n oldTabs =
ParentControl.C ontrols;
RaiseComponentC hanging(TypeDes criptor.GetProp erties(ParentCo ntrol)["TabPages"]);

PJKBaseTabPage P =
(PJKBaseTabPage )(DesignerHost. CreateComponent (typeof(PJKBase TabPage)));

int NewPageNumber = ParentControl.T abCount + 1;
string PageName = "Page " + NewPageNumber.T oString();
P.Text = PageName;
ParentControl.T abPages.Add(P);

RaiseComponentC hanged(TypeDesc riptor.GetPrope rties(ParentCon trol)["TabPages"],
oldTabs, ParentControl.T abPages);
ParentControl.T abPages[NewPageNumber - 1].Name =
PageName.Remove (PageName.LastI ndexOf(" "), 1);
ParentControl.S electedTab = P;
SetVerbs();
}

Dec 19 '06 #9
Mick Doherty wrote:
You were almost there ;-)

The IDesignerHost.C reateComponent( ) method has an overload that takes a Name
value.

int NewPageNumber = ParentControl.T abCount + 1;
PJKBaseTabPage P =
(PJKBaseTabPage )(DesignerHost. CreateComponent (typeof(PJKBase TabPage), "Page"
+ NewPageNumber.T oString()));
P.Text = PageName;
ParentControl.T abPages.Add(P);

However, this will only result in those tabpages added via the 'Add Tab'
verb/smart tag to be custom named and of course, if you remove a tabpage,
the naming algorithm will fail.

I haven't actually tried to modify the Name of the control/component being
added before, so I don't have the correct answer off the top of my head. I
probably won't have a chance to look into it this side of Christmas now, but
if you've not found the answer by the time I do get a chance to look, I'll
post it here.
Thanks Mick, last question ? if my TabPage took a parameter how could I pass it using CreateComponent () ?, cheers
Dec 20 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3971
by: The_Rave | last post by:
Hi everyone, I'm trying to add my own template columns to the property builder of ..NET. E.g. a checkbox column, or an image column. But I can't find the sources of the wizard, or a way to add them to the wizard, via add-in? I tried to capture it with a macro, but all I can't get out of it is the raise event of the wizard, nothing that happens during the wizard. "
5
1803
by: Liz | last post by:
I am trying to add a label to a tab page tabMain.TabPages.Controls.Add(aLabel); and get an error "specified argument was out of the range of valid values. Any ideas???
1
7648
by: RA | last post by:
Hi 1) I want to create a TabPage class in design mode - how do I do it? What type of project should I use? Is it going to be a custom control? 2) I have a TabControl that I would like to add to it the TabPage created in step 1. I don't want to draw the TabPage on the Tabcontrol in design mode, but to have a few TabPage controls that I candynamicaly load to the TabControl at runtime. Thanks
7
3000
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
2729
by: Luc | last post by:
Hi, I have a TabControl and, at runtime, I need to add some tabpages. The problem is that each tabpage is similar to the others and contains several controls. If I do TabControl.TabPages.Add(MyTabPage), a new BLANK tabpage is added. How can I add in few statements a new tabpage as well as its controls (textboxes, labels, etc.)? The first tabpage (that I create at design time) is the "template" to be used for the other tabpages. Is...
3
4857
by: VJ | last post by:
Is there a way to Order Tabpages.. I tried to Use a Class that implements the IComparer and a Compare method as suggested in the MSDN article. "ArrayList.Sort()" and then use the instance of this class to sort like.. tbControl.TabPages.Sort(lstSorter) There seems to be no effect..... I have tried debugging, the sorting seems to happen, but Tabpages don't get rearranged. I even tried Referesh(),
12
1595
by: Bob Jones | last post by:
I have an odd business requirement and I think that the implementation is not correct in the terms of OOP development. Any help on the concepts would be very appreciated! We currently have a custom Page object which is derived from the base Page object. We also have custom controls that derive from a base class that performs custom drawing and inherits from our own IOurControl interface. There is also a special caching layer in the mix...
7
5574
by: davidpryce123 | last post by:
Dear Windows Form Designers I am developing an application that uses a TabControl with several Tabpages. On the different Tabpages I wish to allow users to have the access to the same controls for instance a textbox to enter a date and time string for search.
5
4118
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
0
8628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.