【发布时间】:2016-10-18 11:01:40
【问题描述】:
我已经在 VB.NET 应用程序上工作了大约两年,它的功能与 Windows 资源管理器外壳和文件浏览器的替代品差不多。我刚开始开发一个用户控件,它的作用就像一个按钮,但由一个图片框和一个标签组成。单击项目时发生的情况的代码已经完成,但我遇到了控件属性问题;
我向控件添加了两个属性,一个用于将更改标签文本的“ButtonText”,另一个用于图片框中的“Image”。我通读了微软关于控件属性的文档Creating a Windows Form User Control),他们帮助我为控件添加了属性。
Private bttnTxt As String
Private bttnImg As Image
<Category("Appearance"), Description("The text displayed at the bottom of the button control")>
Public Property ButtonText() As String
Get
Return bttnTxt
End Get
Set(ByVal Value As String)
Label3.Text = Value
End Set
End Property
<Category("Appearance"), Description("The image used in the button control")>
Public Property Image() As Image
Get
Return bttnImg
End Get
Set(ByVal Value As Image)
PictureBox3.BackgroundImage = Value
End Set
End Property
我通过解决方案构建,将新添加的控件添加到我的应用程序主窗体的设计器中,并设置“Image”和“ButtonText”属性的值。但是,当我向自定义属性添加值时,它们会立即恢复为空。
我需要帮助确定为什么我在设计器中设置的值不会保留在属性中。
【问题讨论】:
标签: .net vb.net winforms user-controls