Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Size control to tabpage width

Posted on 2011-09-13
7
Medium Priority
?
1,361 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 400 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 1600 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
Independent Software Vendors: 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!

 
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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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