Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Understanding: TextBox.MaximumSize Property and MinimumSize Property.
 

Understanding: TextBox.MaximumSize Property and MinimumSize Property.

Can someone please explain to me these properties:

MaximumSize Property

MaximumSize Property

Are there any examples out there so I see when, where and to use these properties?

Thanks

Benico26

Benico26  Wednesday, December 05, 2007 12:24 AM
Hi Benico26,

The maximumsize and the minimumsize properties defines the size constraints of the control. The .net layout engine uses this information to layout the controls.

You can change the behaviour of this by overriding the GetPreferredSize method. The GetPreferredSize method is part of the controls class which is inherited by the textbox class.

Here is a little example, which shows how the maximumsize property affects the layout of your controls.
This is the custom control class which inherits the textbox class and uses the maximumsize property:

Code Block

[ToolboxBitmap(typeof(TextBox))]
public class CustTextBox : TextBox
{
public CustTextBox()
{
this.MaximumSize = new Size(40, 30);
}
}

To see it in action, create a new form and add a flowlayoutpanel to it. Now add the custom control to it and you'll see that the size of the textbox is not larger then what you defined, Now change the maximumsize of your control. And add the control again to the flowlayoutpanel. The added textbox will follow the maximumsize constraints.

MSDN:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.getpreferredsize.aspx

More info about preferredsize
http://blogs.msdn.com/jfoscoding/articles/478300.aspx

Layoutengine class
http://msdn2.microsoft.com/en-us/library/system.windows.forms.layout.layoutengine(VS.90).aspx


HawVie  Wednesday, December 05, 2007 8:40 AM
Hi Benico26,

The maximumsize and the minimumsize properties defines the size constraints of the control. The .net layout engine uses this information to layout the controls.

You can change the behaviour of this by overriding the GetPreferredSize method. The GetPreferredSize method is part of the controls class which is inherited by the textbox class.

Here is a little example, which shows how the maximumsize property affects the layout of your controls.
This is the custom control class which inherits the textbox class and uses the maximumsize property:

Code Block

[ToolboxBitmap(typeof(TextBox))]
public class CustTextBox : TextBox
{
public CustTextBox()
{
this.MaximumSize = new Size(40, 30);
}
}

To see it in action, create a new form and add a flowlayoutpanel to it. Now add the custom control to it and you'll see that the size of the textbox is not larger then what you defined, Now change the maximumsize of your control. And add the control again to the flowlayoutpanel. The added textbox will follow the maximumsize constraints.

MSDN:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.getpreferredsize.aspx

More info about preferredsize
http://blogs.msdn.com/jfoscoding/articles/478300.aspx

Layoutengine class
http://msdn2.microsoft.com/en-us/library/system.windows.forms.layout.layoutengine(VS.90).aspx


HawVie  Wednesday, December 05, 2007 8:40 AM

Thanx. I tried it. it works. Now i know how to use it. Thanx again.

Benico26

Benico26  Thursday, December 06, 2007 3:34 AM

You can use google to search for other answers

Custom Search

More Threads

• pre populated listview
• Drawing images and manipulating with that
• Setting treeview node backcolor invalidates entire control
• How to register an activex control
• HTML Textbox
• Designer Serialization (SplitContainer, third parties etc.)
• How do I put a custom glyph next to an existing glyph at design time
• Failure to load designer due to VS2005B2 fault
• C# Designer won't load forms
• Statustrip merge show childforms