Lock height change in a .NET user element in design mode

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.

+4
source share
4 answers

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 } } 
+11
source

Have you tried setting the MinHeight and MaxHeight ?

+1
source

Try using the DesignMode 'property, which means that you are in development mode, that is, in user interface constructor mode. (See MSDN .)

 public int Height() { get { ... } set { if (this.DesignMode) return; else this.myHeight = value; } } 
0
source
 // 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); } 
0
source

All Articles