I'm developing a C# .NET Custom Control and I want to prevent the user, while in design mode, from resizing the Height, while allowing them to reize the Width.
I know this question is a little old, but just in case someone looks for this I'll try to answer it:
You have to override the SetBoundsCore method in your user control. Something like this:
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
}
}
Did you try to set MinHeight
and MaxHeight
properties?
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