Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the text property overridden in user control is not showing at design time

I have a usercontrol which overrides the property Text. But this property is not shown at design time.

If I rename it to caption or value it is shown in properties at design time but Text is not shown.

public Class SomeControl
    Inherits System.Windows.Forms.UserControl

    Public Overrides Property Text() As String
        Get
            Return lblText.Text
        End Get
        Set(ByVal value As String)
            lblText.Text = value
        End Set
    End Property
End Class

What to do?

like image 572
Sachin Chavan Avatar asked May 20 '10 11:05

Sachin Chavan


2 Answers

Added following attributes and the problem is solved.

    <EditorBrowsable(EditorBrowsableState.Always)> _
    <Browsable(True)> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    <Bindable(True)> _
    Public Overrides Property Text() As String
        Get
            Return lblText.Text
        End Get
        Set(ByVal value As String)
            lblText.Text = value
        End Set
    End Property
like image 163
Sachin Chavan Avatar answered Nov 01 '22 13:11

Sachin Chavan


The Text property is defined as:

[Bindable(false), EditorBrowsable(EditorBrowsableState.Never), Browsable(false),
 DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

Meaning, you can't browse it in the property window; you need to override the property attributes defined here (which I don't know if that will work as expected) or just set the property name to something else.

HTH.

like image 41
Brian Mains Avatar answered Nov 01 '22 12:11

Brian Mains