Making an overridden Text property visible in the Visual Studio designer for a UserControl





5.00/5 (8 votes)
Having the property "Text" be available for almost everything in .NET that interacts with the user makes life very simple. But when you create a new UserControl, the Text property doesn't appear in the Properties pane.
Introduction
When you derive a new control from UserControl, you can happily get and set the Text
property from your code - Intellisense finds it, it is a string, it works exactly as you expect.
Except... it doesn't appear in the Properties pane for your control. So your derived control instances can't set individual Text
values at design time. Annoying.
Background
You can try creating a Text
property:
public string Text { get; set; }
...but the compiler complains it already exists, and suggests you try "new
" or "override
". You can try overriding the Text
property:
public override string Text { get; set; }
...and it works fine. Except it doesn't show in the designer.
You can try creating a new Text
property:
public new string Text { get; set; }
... and it works fine, too. Still can't see it in the designer though. You can try setting the EditorBrowserVisibility
:
[EditorBrowsable(EditorBrowsableState.Always)]
public override string Text { get; set; }
...but that doesn't work either.
Showing the Text Property in the designer
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text {get; set;}
Annoying? Yes.
Obvious? No.
Fixed? Yes.
History
Original version.