Solved

Size control to tabpage width

Posted on 2011-09-13
7
1,317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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