Solved

Size control to tabpage width

Posted on 2011-09-13
7
1,198 Views
Last Modified: 2013-12-17
Hi,

I've a tabcontrol and add a tab to:
TabPage rk = new TabPage("NewTab");
tabControl1.TabPages.Add(rk);

The tabcontrol itself has an anchor left, right, top and bottom and I like to add a control to the tabpage and resize it to the whole inner width and height of the tabpage:
rk.Controls.Add(mycontrol);
mycontrol.width = rk.width;

When I now have a look to rk.width I figure out that I ever get 200 as result but the width is 608 ..
So how can I size a contol inside the tabepage to be "fullsize"?

Thanks

Andre
0
Comment
Question by:andre72
7 Comments
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 100 total points
ID: 36530000
It would be better to dock the control inside the tabPage than to anchor the control:
rk.Dock(DockStyle.Fill);

Hope that helps.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 400 total points
ID: 36530009
Anchor it too, or even easier, Dock it.

mycontrol.Dock = System.Windows.Forms.DockStyle.Fill;

Anchor and Dock work on the container. If the container is a Form, they adjust to the Form. If the container is a TabPage, they adjust the the TabPage.
0
 
LVL 12

Expert Comment

by:starlite551
ID: 36532584
TRY THIS ONE :
TabPage rk = new TabPage("NewTab");
tabControl1.TabPages.Add(rk);
rk.Controls.Add(mycontrol);
mycontrol.Dock = System.Windows.Forms.DockStyle.Fill;
mycontrol.Anchor = System.Windows.Forms.AnchorStyle.Top | System.Windows.Forms.AnchorStyle.Left | System.Windows.Forms.AnchorStyle.Bottom | System.Windows.Forms.AnchorStyle.Right;

Open in new window

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 12

Expert Comment

by:starlite551
ID: 36532598
Sorry about a mistake in the above code it should have been "AnchorStyles" and NOT "AnchorStyle" ...
Heres is the correct code :
TabPage rk = new TabPage("NewTab");
tabControl1.TabPages.Add(rk);
rk.Controls.Add(mycontrol);
mycontrol.Dock = System.Windows.Forms.DockStyle.Fill;
mycontrol.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;

Open in new window

0
 
LVL 12

Expert Comment

by:starlite551
ID: 36532604
If above code doesn`t work you may try this out instead :  
TabPage rk = new TabPage("NewTab");
tabControl1.TabPages.Add(rk);
mycontrol.Dock = System.Windows.Forms.DockStyle.Fill;
mycontrol.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
rk.Controls.Add(mycontrol);

Open in new window

0
 
LVL 40
ID: 36532610
Strange, how, 6 hours later, somebody post exactly the same answer, simply adding a useless line.

Anchor is useless when you use Dock.
0
 

Author Closing Comment

by:andre72
ID: 36534321
Thanks for your support
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now