Search code examples
.netvb.netwinformsuser-controls

User Control properties not saving in designer


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.

I've attached an image here to demonstrate my problem.


Solution

  • 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