在设计时防止高度尺寸

我正在开发自定义用户控件。 如何在设计时界面中防止控件的高度被修改。

您可以通过在调用基类实现之前更改height值来覆盖SetBoundsCore方法并禁止更改高度。

 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); } 

您可以从Control类重写Height属性,然后设置BrowsableAttribute以防止它显示在属性窗口中

您还可以查看属性和设计时支持