HighTechTalks DotNet Forums  

Resizing TabControl at runtime

VB.net Controls microsoft.public.dotnet.languages.vb.controls


Discuss Resizing TabControl at runtime in the VB.net Controls forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nigel V Thomas
 
Posts: n/a

Default Resizing TabControl at runtime - 09-13-2009 , 05:20 AM






Hi

I have an issue with resizing the TabControl at runtime. Here's what I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as required - OK
5.Resize the TabControl to the size of the largest of the Panels contained
in the TapPages - This is where I am having problems. I cannot get the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short by 2 or 3

Can anyone help with this please.

Nigel


Reply With Quote
  #2  
Old   
Mick Doherty
 
Posts: n/a

Default Re: Resizing TabControl at runtime - 09-13-2009 , 08:24 AM






Hi Nigel,

Why are you adding a Panel to the TabPage? TabPage inherits from Panel and
so basically TabPage is a Panel.

Take a look at the difference between TabControl.DisplayRectangle.Size and
Panel.Size. The difference between the 2 should give you the amount by which
you need to resize.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi

I have an issue with resizing the TabControl at runtime. Here's what I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as required -
OK
5.Resize the TabControl to the size of the largest of the Panels contained
in the TapPages - This is where I am having problems. I cannot get the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short by 2
or 3

Can anyone help with this please.

Nigel

Reply With Quote
  #3  
Old   
Nigel V Thomas
 
Posts: n/a

Default Re: Resizing TabControl at runtime - 09-13-2009 , 11:18 AM



Mick

Thanks for the input.

I've removed the TabStrip.Controls.Add Panel but I still have issues with
resizing.

Any suggestions on how I access the Panel.Size please

Nigel
"Mick Doherty" wrote:

Quote:
Hi Nigel,

Why are you adding a Panel to the TabPage? TabPage inherits from Panel and
so basically TabPage is a Panel.

Take a look at the difference between TabControl.DisplayRectangle.Size and
Panel.Size. The difference between the 2 should give you the amount by which
you need to resize.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in message
news:7B48227D-01C8-42FC-991A-FE9B863DF739 (AT) microsoft (DOT) com...
Hi

I have an issue with resizing the TabControl at runtime. Here's what I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as required -
OK
5.Resize the TabControl to the size of the largest of the Panels contained
in the TapPages - This is where I am having problems. I cannot get the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short by 2
or 3

Can anyone help with this please.

Nigel

Reply With Quote
  #4  
Old   
Mick Doherty
 
Posts: n/a

Default Re: Resizing TabControl at runtime - 09-14-2009 , 12:50 PM



Hi Nigel,

Some code showing how you are adding the TabPages and associated controls
would help to give you an answer.

Don't do this:
someTabPage.Controls.Add(New Panel)


Do do this:
Dim newPanel As New Panel
someTabPage.Controls.Add (newPanel)

Using the latter method gives you easy access to all of the newly created
Panels properties, including Size.

Of course, the exact code to use may differ depending upon other
requirements.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote

Quote:
Mick

Thanks for the input.

I've removed the TabStrip.Controls.Add Panel but I still have issues with
resizing.

Any suggestions on how I access the Panel.Size please

Nigel
"Mick Doherty" wrote:

Hi Nigel,

Why are you adding a Panel to the TabPage? TabPage inherits from Panel
and
so basically TabPage is a Panel.

Take a look at the difference between TabControl.DisplayRectangle.Size
and
Panel.Size. The difference between the 2 should give you the amount by
which
you need to resize.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in
message
news:7B48227D-01C8-42FC-991A-FE9B863DF739 (AT) microsoft (DOT) com...
Hi

I have an issue with resizing the TabControl at runtime. Here's what
I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as
required -
OK
5.Resize the TabControl to the size of the largest of the Panels
contained
in the TapPages - This is where I am having problems. I cannot get the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short by
2
or 3

Can anyone help with this please.

Nigel

Reply With Quote
  #5  
Old   
Nigel V Thomas
 
Posts: n/a

Default Re: Resizing TabControl at runtime - 09-15-2009 , 03:57 AM



Hi Mick

I'm missing something.

You wrote:
Quote:
Why are you adding a Panel to the TabPage? TabPage inherits from Panel
and
so basically TabPage is a Panel.
So I don't get your suggestion of adding a Panel!

To be clear (I may not have been) I am dynamically adding tabpages to a
tabcontrol and controls to the tabpages at run time.

My issue is that I am trying to calculate the size of the TabControl once
all tabpages and controls have been added so I can resize the form. The is no
AutoSize for the TabControl (unfortunately)

Nigel


"Mick Doherty" wrote:

Quote:
Hi Nigel,

Some code showing how you are adding the TabPages and associated controls
would help to give you an answer.

Don't do this:
someTabPage.Controls.Add(New Panel)


Do do this:
Dim newPanel As New Panel
someTabPage.Controls.Add (newPanel)

Using the latter method gives you easy access to all of the newly created
Panels properties, including Size.

Of course, the exact code to use may differ depending upon other
requirements.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in message
news:1C32F3C2-18D1-406A-B744-17DBF6662C4E (AT) microsoft (DOT) com...
Mick

Thanks for the input.

I've removed the TabStrip.Controls.Add Panel but I still have issues with
resizing.

Any suggestions on how I access the Panel.Size please

Nigel
"Mick Doherty" wrote:

Hi Nigel,

Why are you adding a Panel to the TabPage? TabPage inherits from Panel
and
so basically TabPage is a Panel.

Take a look at the difference between TabControl.DisplayRectangle.Size
and
Panel.Size. The difference between the 2 should give you the amount by
which
you need to resize.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in
message
news:7B48227D-01C8-42FC-991A-FE9B863DF739 (AT) microsoft (DOT) com...
Hi

I have an issue with resizing the TabControl at runtime. Here's what
I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as
required -
OK
5.Resize the TabControl to the size of the largest of the Panels
contained
in the TapPages - This is where I am having problems. I cannot get the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short by
2
or 3

Can anyone help with this please.

Nigel

Reply With Quote
  #6  
Old   
Mick Doherty
 
Posts: n/a

Default Re: Resizing TabControl at runtime - 09-15-2009 , 12:56 PM



Hi Nigel,

In your original message you stated as step 3. "Add TabPages as required and
a Panel to each TabPage - OK"

If, in fact, you are not adding a Panel then that makes more sense.

Just as a query, you do know that you can set AutoScroll on the TabPage so
that you can scroll to any content which does not fit in the Display Area?

To get the size of the TabPage you would use the TabPages GetPreferredSize()
method after having added the page to the TabControl. You can then compare
this size to the tabpages ClientSize in order to get the difference.

i.e.

--8< -----------------------------
Size prefferedSize = tabpage.GetPreferredSize(Size.Empty);
Size currentSize = tabpage.ClientSize;

if (prefferedSize.Width > currentSize.Width)
tabControl.Width += prefferedSize.Width - currentSize.Width;

if (prefferedSize.Height > currentSize.Height)
tabControl.Height += prefferedSize.Height - currentSize.Height;
--8< -----------------------------


Regards,

Mick Doherty
http://dotnetrix.co.uk/tabcontrol.htm


"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi Mick

I'm missing something.

You wrote:
Why are you adding a Panel to the TabPage? TabPage inherits from Panel
and
so basically TabPage is a Panel.

So I don't get your suggestion of adding a Panel!

To be clear (I may not have been) I am dynamically adding tabpages to a
tabcontrol and controls to the tabpages at run time.

My issue is that I am trying to calculate the size of the TabControl once
all tabpages and controls have been added so I can resize the form. The is
no
AutoSize for the TabControl (unfortunately)

Nigel


"Mick Doherty" wrote:

Hi Nigel,

Some code showing how you are adding the TabPages and associated controls
would help to give you an answer.

Don't do this:
someTabPage.Controls.Add(New Panel)


Do do this:
Dim newPanel As New Panel
someTabPage.Controls.Add (newPanel)

Using the latter method gives you easy access to all of the newly created
Panels properties, including Size.

Of course, the exact code to use may differ depending upon other
requirements.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in
message
news:1C32F3C2-18D1-406A-B744-17DBF6662C4E (AT) microsoft (DOT) com...
Mick

Thanks for the input.

I've removed the TabStrip.Controls.Add Panel but I still have issues
with
resizing.

Any suggestions on how I access the Panel.Size please

Nigel
"Mick Doherty" wrote:

Hi Nigel,

Why are you adding a Panel to the TabPage? TabPage inherits from Panel
and
so basically TabPage is a Panel.

Take a look at the difference between TabControl.DisplayRectangle.Size
and
Panel.Size. The difference between the 2 should give you the amount by
which
you need to resize.

Regards,

Mick Doherty

"Nigel V Thomas" <NigelVThomas (AT) discussions (DOT) microsoft.com> wrote in
message
news:7B48227D-01C8-42FC-991A-FE9B863DF739 (AT) microsoft (DOT) com...
Hi

I have an issue with resizing the TabControl at runtime. Here's what
I'm
trying to do.

1. Create a form
2.Dynamically add a TabControl - OK
3.Add TabPages as required and a Panel to each TabPage - OK
4.Add controls to the Panel's as requried and resize Panel as
required -
OK
5.Resize the TabControl to the size of the largest of the Panels
contained
in the TapPages - This is where I am having problems. I cannot get
the
TabControl to resize correctly. I'm using TabControl.ItemSize and
TabControl.ClientSize but the size caluclation always comes up short
by
2
or 3

Can anyone help with this please.

Nigel

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.