Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1383
  • Last Modified:

Size control to tabpage width

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
andre72
Asked:
andre72
2 Solutions
 
Luis PérezSoftware Architect in .NetCommented:
It would be better to dock the control inside the tabPage than to anchor the control:
rk.Dock(DockStyle.Fill);

Hope that helps.
0
 
Jacques Bourgeois (James Burger)Commented:
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
 
starlite551Commented:
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
starlite551Commented:
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
 
starlite551Commented:
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
 
Jacques Bourgeois (James Burger)Commented:
Strange, how, 6 hours later, somebody post exactly the same answer, simply adding a useless line.

Anchor is useless when you use Dock.
0
 
andre72Author Commented:
Thanks for your support
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now