Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我如何告诉设计器我的自定义winforms控件具有固定高度?_C#_.net_Winforms_Designer - Fatal编程技术网

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命名空间的引用