C# 我如何告诉设计器我的自定义winforms控件具有固定高度?
我制作了一个自定义控件,并重写了C# 我如何告诉设计器我的自定义winforms控件具有固定高度?,c#,.net,winforms,designer,C#,.net,Winforms,Designer,我制作了一个自定义控件,并重写了SetBoundsCore,这样控件的高度是固定的。我希望设计器显示与NumericUpDown相同类型的调整大小框-每端只有一个-以便很明显控件具有固定高度。如何告诉设计器我的控件具有固定高度?您必须将designer属性应用于UserControl: [Designer(typeof(UCDesigner))] public partial class UserControl1 : UserControl { public UserControl1()
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命名空间的引用。您必须将
设计器
属性应用于用户控件
:
[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命名空间的引用