【问题标题】:How do I tell the designer that my custom winforms control has a fixed height?如何告诉设计师我的自定义 winforms 控件具有固定高度?
【发布时间】:2009-07-24 08:38:27
【问题描述】:

我制作了一个自定义控件并覆盖了SetBoundsCore,这样控件的高度就固定了。我希望设计器显示与NumericUpDown 相同的大小调整框 - 每端只有一个 - 以便清楚地看到控件具有固定高度。如何告诉设计者我的控件是固定高度的?

【问题讨论】:

    标签: c# .net winforms designer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      相关资源
      最近更新 更多