Winforms Designer 支持选择类型和控件
我有一个 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 Control
s 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 Type
s ?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设计器的默认实现已处理 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.