473,729 Members | 2,331 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 18137
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
3972
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
1804
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
7651
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
3011
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
2733
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
4862
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
1597
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
5581
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
4123
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
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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
9281
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
9200
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
9142
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
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.