I am developing C # .NET Custom Control, and I want the user, while in development mode, not to resize Height, allowing them to reuse Width.
I know this question is a little old, but just in case someone is looking for it, I will try to answer it:
You need to override the SetBoundsCore method in your user control. Something like that:
protected override void SetBoundsCore( int x, int y, int width, int height, BoundsSpecified specified) { // EDIT: ADD AN EXTRA HEIGHT VALIDATION TO AVOID INITIALIZATION PROBLEMS // BITWISE 'AND' OPERATION: IF ZERO THEN HEIGHT IS NOT INVOLVED IN THIS OPERATION if ((specified & BoundsSpecified.Height) == 0 || height == DEFAULT_CONTROL_HEIGHT) { base.SetBoundsCore(x, y, width, DEFAULT_CONTROL_HEIGHT, specified); } else { return; // RETURN WITHOUT DOING ANY RESIZING } }
Have you tried setting the MinHeight and MaxHeight ?
MinHeight
MaxHeight
Try using the DesignMode 'property, which means that you are in development mode, that is, in user interface constructor mode. (See MSDN .)
DesignMode
public int Height() { get { ... } set { if (this.DesignMode) return; else this.myHeight = value; } }
// Override SetBoundsCore method to set resize limits
// this code captures the height up to 20, and other attributes can be changed
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { // Set a fixed height for the control. base.SetBoundsCore(x, y, width, 20, specified); }