代码之家  ›  专栏  ›  技术社区  ›  DRapp

防止在设计时调整高度

  •  3
  • DRapp  · 技术社区  · 15 年前

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

    2 回复  |  直到 15 年前
        1
  •  2
  •   Jeff Yates    15 年前

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

    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);
    }
    
        2
  •  0
  •   armannvg    15 年前

    可以重写控件类中的“高度”属性,然后设置 BrowsableAttribute 防止它显示在属性窗口中

    你也可以看看 Attributes and Design-Time Support