Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't my Custom Control's Text property show up in the Properties window?

I have a user control that inherits from UserControl. It's a button so I'm trying to make the text in the button, change-able by using the Text property like the real buttons, instead of naming my own like _Text. I have the following code but it doesn't work (ie it doesn't show up in the Property Window). The name of the label is ContentPresenter

public override string Text
{
    get
    {
        return ContentPresenter.Text;
    }
    set
    {
        ContentPresenter.Text = value;
    }
}
like image 558
Oztaco Avatar asked Apr 16 '12 19:04

Oztaco


People also ask

Can t see Properties in Visual Studio?

If the Properties window is not visible, open it by pressing F4. Open the MyToolWindow window. You can find it in View > Other Windows. The window opens and the public properties of the window pane appear in the Properties window.

How do I show the Properties window in Visual Studio?

You can find Properties Window on the View menu. You can also open it by pressing F4 or by typing Properties in the search box. The Properties window displays different types of editing fields, depending on the needs of a particular property.

Which property show the Text on control in asp net?

Remarks. Use the Text property to specify or determine the text content of the Label control. This property is commonly used to programmatically customize the text that is displayed in the Label control.

How do you change Text properties in Visual Studio?

In most cases you will edit the Text to change the text that an object displays. You can do this by selecting the property in the Property window or by typing while the object is selected - Visual Studio assumes that you want to change the text property in this case.


1 Answers

UserControl goes to significant effort to hide the Text property. From the metadata:

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Bindable(false)]
    public override string Text { get; set; }

You can make it visible by overriding those attributes in your code:

    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Bindable(true)]
    public override string Text 
    { 
        get { return ContentPresenter.Text; } 
        set { ContentPresenter.Text = value; } 
    } 

I'm not promising that's enough to make it work, but it probably is.

like image 192
Igby Largeman Avatar answered Oct 19 '22 22:10

Igby Largeman