Possible Duplicate:
Text property in a UserControl in C#
How do I mark the Text property of a UserControl as browsable?
A .NET UserControl class has a Text property.
Unfortunately the Text property of a UserControl isn't browsable:
//
//
// Returns:
// The text associated with this control.
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text { get; set; }
In my UserControl I want to expose the Text property (i.e. make it "browsable") in the properties window. I tried blindly declaring it browsable:
[Browsable(true)]
public override string Text { get; set; }
and now it appears in the properties window, except now it does nothing.
I tried blindly calling base.Text to bring back the functionality:
[Browsable(true)]
public override string Text { get {return base.Text;} set { base.Text = value; this.Invalidate(); } }
and now the property does function at design-time, but the property value is not persisted to the Form.Designer.cs and it's InitalizeComponent code.
What is the proper way to expose the UserControl Text property so that it:
- is browsable in the properties window
- is functional
- is persisted in the form designer
and, as a bonus:
- know when it changes