【问题标题】:Filtering the droplist of property in User Control过滤用户控件中的属性下拉列表
【发布时间】:2018-02-16 18:50:44
【问题描述】:

我在用户控件中添加了以下属性

private Control _associatedControl = new Control();
[Description("Sets Asociated Control"),
 Category("EzData"),
 DefaultValue(""),
 Browsable(true)]
public Control AssociatedControl
{
    get => _associatedControl;
    set
    {
        _associatedControl = value;
    }
}

在设计时控件列出了父窗体中的所有控件。 我的问题如何使列表仅包含某些域中的控件(我设计的其他用户控件)。

【问题讨论】:

    标签: c# .net winforms user-controls windows-forms-designer


    【解决方案1】:

    设计者根据属性的类型填充列表。例如,如果属性类型为Button,则列表将仅包含按钮控件。

    您可以为控件使用基本类型(或接口),然后声明具有相同类型的属性。这样,设计器将仅在列表中显示具有该类型(或接口)的对象。

    例如声明属性:

    public MyBaseControl AssociatedControl { get; set; }
    

    然后设计器将列出所有源自MyBaseControl的控件实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-09
      • 2021-07-25
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      • 2011-03-17
      • 1970-01-01
      • 2019-05-20
      相关资源
      最近更新 更多