views:

40

answers:

2

I'm working on a custom user control. How can I prevent the HEIGHT ONLY of the control from being modified during the design-time interface.

+2  A: 

You can override the SetBoundsCore method and disallow changes to height by changing the height value before calling the base class implementation.

private const int FixedHeightIWantToKeep = 100;

protected override void SetBoundsCore(
    int x,
    int y,
    int width,
    int height,
    BoundsSpecified specified)
{
    // Fixes height at 100 (or whatever fixed height is set to).
    height = this.FixedHeightIWantToKeep;
    base.SetBoundsCore(x, y, width, height, specified);
}
Jeff Yates
A: 

You can override the Height attribute from the Control class and then set the BrowsableAttribute to prevent it from being displayed in the properties windows

You can also take a look at Attributes and Design-Time Support

armannvg