繁体   English   中英

如何告诉设计师我的自定义winforms控件有一个固定的高度?

[英]How do I tell the designer that my custom winforms control has a fixed height?

我已经制作了一个自定义控件并覆盖了SetBoundsCore ,以便控制的高度是固定的。 我希望设计师能够像NumericUpDown一样显示相同类型的调整大小 - 每端只有一个 - 这样很明显控件有一个固定的高度。 如何告诉设计师我的控件有一个固定的高度?

您必须将Designer属性应用于UserControl

[Designer(typeof(UCDesigner))]
public partial class UserControl1 : UserControl {

  public UserControl1() {
    InitializeComponent();
  }

}

UCDesigner类定义如下:

class UCDesigner : System.Windows.Forms.Design.ControlDesigner {

  public override System.Windows.Forms.Design.SelectionRules SelectionRules {
    get {
      return (base.SelectionRules & ~(SelectionRules.BottomSizeable | SelectionRules.TopSizeable));
    }
  }

}

注意:您必须添加对System.Design命名空间的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM