我制作了一个自定义控件并重写了 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 命名空间的引用。
