用户控制 - 自定义属性 [英] User Control - Custom Properties
问题描述
我已经开发了在Visual Studio(的WinForms C#)用户控制有问题。
I have developed a User Control in Visual Studio (WinForms C#) and have a question.
我需要我的用户控件的用户才能够改变某些字符串值,我希望他们能够给用户控件添加到其形式和点击它,弹出属性面板在我的用户控件的自定义属性将显示。
I need the user of my User Control to be able to change certain string values and I would like them to be able to add the user control to their Form and click on it to bring up the Properties Pane where my User Control's custom properties will be displayed.
我怎么能为我的用户控制自己的自定义属性?例如:
How can I have my own custom properties for my user control? For example:
我的用户控件包含一个文本框,我希望用户能够通过一个名为文本或属性来改变文本框的值值。在设计时的属性。
My user control contains a TextBox, and I would like the user to be able to change the value of that TextBox via a property named "Text" or "Value" in the properties at Design-Time.
推荐答案
您通过对性能的属性,这样做:
You do this via attributes on the properties, like this:
[Description("Test text displayed in the textbox"),Category("Data")]
public string Text {
get { return myInnerTextBox.Text; }
set { myInnerTextBox.Text = value; }
}
类别是根据该属性将出现在Visual Studio中的标题属性框。 这里有一个更完整的参考MSDN ,包括类别列表。
这篇关于用户控制 - 自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!