替换组件中的默认属性 [英] Replace the default property in a component

查看:83
本文介绍了替换组件中的默认属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个继承自TextBox的组件。


我想创建一个覆盖或替换默认值的属性 属性"文本"作为默认属性,因此当组件放置在表单上时,属性表中的"数据绑定"|"高级"对话框将默认显示我的新属性


换句话说,我的新属性将在此对话框打开时获得焦点,而不是Text属性。


我尝试将此属性声明为Default。 Visual Studio告诉我必须使用必要的参数,我已经完成了。但是当这个新组件放在表单上时,designer.vb不知道如何为参数提供值。我很难过。


如何做到这一点?感谢您的帮助。

解决方案

我不知道您的属性是什么数据类型,但是使用DefaultPropertyAttribute属性设置默认属性。  请参阅 http://msdn.microsoft.com/en -us /库/ system.componentmodel.defaultpropertyattribute.aspx

I have built a component which inherits from TextBox.

I would like to create a property which overrides or replaces default property 'Text' as the default property, so that when the component is placed on a form, the Databindings|Advanced dialog in the property sheet shows my new property as default.

In other words, my new property will receive the focus when this dialog opens, as opposed to the Text property.

I tried declaring this property as Default. Visual Studio tells me I must use a required parameter, which I've done. But when this new component is placed on a form, the designer.vb has no idea how to provide the value for the argument. I'm stumped.

How can this be done? Thanks for any help.

解决方案

I don't know what data type your property is, but default properties are set using the DefaultPropertyAttribute attribute.  See http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultpropertyattribute.aspx.


这篇关于替换组件中的默认属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆