Reputation: 36
I've been working on a VB.NET application for about two years now that functions much as a Windows Explorer shell and file browser replacement. I just started to develop a user control that will act like a button but consists of one picturebox and one label. The code for what happens when the item is clicked is already finished but I'm having a problem with the control's properties;
I added two properties to the control, one for the "ButtonText" that will change the text of the label, and one for the "Image" in the picturebox. I read through Microsoft's documentation on control properties Creating a Windows Form User Control) and they helped me add properties to the 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
I built by solution, added the newly added control to my designer of my application's main form and set the values of the "Image" and "ButtonText" properties. However when I add a value to my custom properties, they immediately revert back to nothing.
I need help determining why the values I set in the designer wont stay in the properties.
Upvotes: 0
Views: 1753
Reputation: 671
My problem was that I needed to override the clone function. See below code example.
Hopefully this helps save some time for someone.
Public Class CustomClass_DatGridViewColumn
Inherits DataGridViewComboBoxColumn
Private propertyValue As String = ""
Public Overrides Function Clone() As Object
Dim col As CustomClass_DatGridViewColumn = CType(MyBase.Clone(), CustomClass_DatGridViewColumn)
col.myProperty = propertyValue
Return col
End Function
<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Category("Data"), .Description("description")>
Public Property myProperty As String
Get
Return propertyValue
End Get
Set(ByVal value As String)
propertyValue = value
End Set
End Property
End Class
Upvotes: 0
Reputation: 81620
You aren't saving anything to your variable:
Public Property ButtonText() As String
Get
Return bttnTxt
End Get
Set(ByVal Value As String)
bttnTxt = Value
Label3.Text = Value
End Set
End Property
Upvotes: 1