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
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.
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 .
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".
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.
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.
Bounds
is the actual size its drawn at
ClientSize
is the size minus any scroll bars
Control.PreferredSize
is what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With