Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make WinForms UserControl fill the size of its container

I am trying to create a multilayout main screen application. I have some buttons at the top that link to the main section of the application (e.g. management window for each entity in the Model)

Clicking any of these button displays the associated UserControl in a Panel. The Panel holds the UserControls that in turn holds the UI.

The WinForms UserControl does not have the Anchor or Dock property.

I have tried setting property of UserControl

AutoSize=True 

And

private void ManageUsersControl_Load(object sender, EventArgs e) {         this.Width = this.Parent.Width;         this.Height = this.Parent.Height; } 

But these did not work.
Note: I load this control dynamically at runtime

like image 635
codingbiz Avatar asked Jun 03 '12 15:06

codingbiz


People also ask

How do I fix winform size?

Right click on your form and go to properties. Then go to Layout options,see there are a property named Size. Change it as your need as width and length wise.

How do I make WinForms resizable?

To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill . It's fairly intuitive once you start using it. For example, if you have OK/Cancel buttons in the lower right of your dialog, set the Anchor property to Bottom and Right to have them drag properly on the form.

How do I increase the size of a CheckBox in WinForms?

There's an AutoSize option in the Properties windows; if you turn that off by changing it to False , you will be able to modify the size of your CheckBox .

What is UserControl in WinForms?

A UserControl is a collection of controls placed together to be used in a certain way. For example you can place a GroupBox that contains Textbox's, Checkboxes, etc. This is useful when you have to place the same group of controls on/in multiple forms or tabs.


1 Answers

Try setting the Dock property to Fill:

private void ManageUsersControl_Load(object sender, EventArgs e) {         this.Dock = DockStyle.Fill; } 

I would also set AutoSize to the default, I believe is False. See how that works ...

like image 156
IAbstract Avatar answered Sep 21 '22 19:09

IAbstract