The best way to ensure a particular height or width for a control is to override the control’s SetBoundsCore method.
This sample shows a Button which has a fixed height and width. The same technique can be used to set the upper and lower bounds on sizes.
[C#]
using System.Windows.Forms;
public class ButtonWithConstrainedSize : Button
{
private static int fixedHeight = 50;
private static int fixedWidth = 50;
protected override void SetBoundsCore( int x, int y, int width, int height,
BoundsSpecified specified )
{
base.SetBoundsCore( x, y, fixedWidth, fixedHeight, specified );
}
}
Share with