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.
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?