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

时间:2009-07-24 08:38:27

标签: c# .net winforms designer

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

1 个答案:

答案 0 :(得分:4)

您必须将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命名空间的引用。