The text property in user control is no longer relevant

I am creating a custom button control and have difficulty with my Text property. All that I type, remains only when you open the form designer window. When I close the form designer and open it again, the Text property changes the value to "". Also, if I run the program, it loses the value entered during development.

I also have an Image property for my control, which works fine.

Here are some of my codes:

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class BlackButton

Private iText As String
Private iImage As Image

''' <summary>
''' Gets/Sets the text displayed in the button.
''' </summary>
<Browsable(True), Description("Gets or sets the text displayed on the button")> _
Public Shadows Property Text() As String
    Get
        Return iText
    End Get
    Set(ByVal value As String)
        iText = value
        ReDrawMe()
    End Set
End Property

''' <summary>
''' Gets/Sets the image to be displayed on the button
''' </summary>
<Browsable(True), Description("Gets or sets the image displayed on the button")> _
Public Shadows Property Image() As Image
    Get
        Return iImage
    End Get
    Set(ByVal value As Image)
        iImage = value
        ReDrawMe()
    End Set
End Property

I carefully combed my code and made sure that I did not restart it anywhere.

Thanks in advance for your help.

+3
source share
2 answers

It seems to need to add a property:

<Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Overrides Property Text() As String
    Get
        Return MyBase.Text
    End Get
    Set(ByVal value As String)
        MyBase.Text = value
        LabInfo.Text = MyBase.Text
    End Set
End Property
+1

- . Shadows. , Override , , VS Text Image.

EDIT: , Overrides. Image Overloads . :

Imports System.ComponentModel

UserControl1

Dim _Text As String
Dim _Image As Image

<Browsable(True), Description("Gets or sets the text displayed on the button")> _
Overrides Property Text() As String
    Get
        Return _Text
    End Get
    Set(ByVal value As String)
        _Text = value
        'This line just for update
        'the UI when I design to check
        'if the values are saved.
        MyBase.Text = value
    End Set
End Property

<Browsable(True), Description("Gets or sets the image displayed on the button")> _
Overloads Property Image() As Image
    Get
        Return _Image
    End Get
    Set(ByVal value As Image)
        _Image = value
        'ReDrawMe()
    End Set
End Property

+1

All Articles