Solved

Size control to tabpage width

Posted on 2011-09-13
7
1,262 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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