关于vb.net:为什么在设计时未显示用户控件中覆盖的text属性

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

我有一个用户控件,它覆盖了属性Text。但是此属性不会在设计时显示。

如果我将其重命名为标题或值,则会在设计时显示在属性中,但不会显示文本。

1
2
3
4
5
6
7
8
9
10
11
12
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

该怎么办?


添加了以下属性,问题得以解决。

1
2
3
4
5
6
7
8
9
10
11
12
    <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


Text属性定义为:

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

意味着,您无法在属性窗口中浏览它;您需要覆盖此处定义的属性属性(我不知道这是否可以按预期工作)或仅将属性名称设置为其他名称。

HTH。