Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms - How do you get the size a Control "wants" to be?

Tags:

c#

.net

winforms

When a Control is docked in a container (like a Panel) and is too wide to be shown (so a scroll bar appears), Control.Width seems to return the visible width of the Control (the top arrow in the picture).

How do you get the width that the Control "wants" to be? i.e. its full width that you'd see if you didn't have to scroll (the bottom arrow in the picture).

alt text http://img19.imageshack.us/img19/372/size.png

like image 784
xyz Avatar asked Apr 14 '09 16:04

xyz


People also ask

How do I fix winform size?

You can restrict the size of a form by setting it's MaximumSize and MinimumSize properties. This will help you control the maximum and minimum size the form can be resized to. Also note that WindowState property of the form plays a part in how the form can be resized.

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 .

How do I make WinForms resizable?

Creating our Resizable FormOpen Visual Studio and select "Windows Forms Application" from the list of available templates and name it "DynamicallyPositioningControls". Rename your form to "frmDynamicResizing" by setting its Name property and sets its Text property to "Dynamic Resizing Form".

How do I dock controls in Windows Forms?

Select the control in the designer. In the Properties window, select the arrow to the right of the Dock property. Select the button that represents the edge of the container where you want to dock the control. To fill the contents of the control's form or container control, press the center box.


2 Answers

There are two different properties of controls that you might find useful for this purpose. There is the DefaultSize which is the Size of the control when it is initially created, and then there is the PreferredSize which is the size the control can fit into so to speak. All controls have these properties and PreferredSize should be the one you're looking for.

like image 70
Kasper Holdum Avatar answered Sep 22 '22 08:09

Kasper Holdum


Bounds is the actual size its drawn at

ClientSize is the size minus any scroll bars

Control.PreferredSize is what you want

like image 35
Hath Avatar answered Sep 23 '22 08:09

Hath