簡體   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