Winforms Designer 支持选择类型和控件

发布于 2024-08-20 09:54:49 字数 943 浏览 4 评论 0原文

我有一个 BindingSource 的子类,它只是为了我们的特殊需要而对其进行了一些扩展,并且我想为 VS2008 设计器支持它。

我有三个属性,我希望获得设计者的支持,其中两个应设置为表单上的其他 Control,一个应设置为 Type

在 den Designer 中显示它们以及设置默认值 null 非常容易,但是我如何设法让 VS 选择可用的控件(最好仅是所需的类型)和/或 Type

这是到目前为止的属性代码,欢迎任何提示,因为我对 VS-Designer 支持一无所知。

public class BindingSourceEx
    : BindingSource
{
    [DisplayName("DataSourceType")]
    [Description("Sets the type to bind to.")]
    public Type DataSourceType
    {
        get;
        set;
    }

    [DisplayName("BindingNavigator")]
    [DefaultValue(null)]
    [Description("Sets the BindingNavigatorQ1 to use.")]
    public BindingNavigatorEx BindingNavigator
    {
        get;
        set;
    }

    [DisplayName("DataGridView")]
    [DefaultValue(null)]
    [Description("Sets the DataGridViewQ1 to use.")]
    public DataGridViewEx DataGridView
    {
        get;
        set;
    }
}

I have a Subclass of a BindingSource that just extends it a bit for our special needs, and I would like to support it for the VS2008 Designer.

I have three properties, that I would like to get designer support for, two of them should be set to other Controls on the form, one should be set to a Type.

Displaying them in den Designer as well as setting a default value of null was quite easy, but how do I manage to get VS to select availlable Controls (ideally of desired type only) and or Types ?

Here's the code for the properties so far, any hint is welcome, since I do not know anything over VS-Designer support.

public class BindingSourceEx
    : BindingSource
{
    [DisplayName("DataSourceType")]
    [Description("Sets the type to bind to.")]
    public Type DataSourceType
    {
        get;
        set;
    }

    [DisplayName("BindingNavigator")]
    [DefaultValue(null)]
    [Description("Sets the BindingNavigatorQ1 to use.")]
    public BindingNavigatorEx BindingNavigator
    {
        get;
        set;
    }

    [DisplayName("DataGridView")]
    [DefaultValue(null)]
    [Description("Sets the DataGridViewQ1 to use.")]
    public DataGridViewEx DataGridView
    {
        get;
        set;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两个我 2024-08-27 09:54:49

设计器的默认实现已处理 BindingNavigator 和 DataGridView 属性。属性网格使用组合框让您选择与控件类型匹配的控件。例如,您必须在窗体上放置一个 BindingNavigatorQ1 控件才能在组合框中获取除 None 之外的任何内容。

Type 属性更难,您至少需要一个 TypeConverter 来在 Type 值和字符串之间进行转换。不太确定这应该是一个可设计的属性,您想要绑定的类型在设计时肯定还不存在,仅在编译所有程序集的运行时存在。

The default implementation of the designer already takes care of the BindingNavigator and DataGridView properties. The property grid uses a combobox to let you select the control that matches the control type. You'd have to drop, say, a BindingNavigatorQ1 control on the form to get anything other than None in the combobox.

The Type property is a tougher, you'll need at least a TypeConverter to convert between the Type value and a string. Not so sure this ought to be a designable property, the type you want to bind to surely doesn't yet exist at design time, only at runtime when all the assemblies are compiled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文