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:
and, as a bonus:
You're on the right track; just add [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
To find out when it changes, override OnTextChanged:
protected override void OnTextChanged (EventArgs eventArgs)
{
System.Diagnostics.Trace.WriteLine("OnTextChanged(): eventArgs: " + eventArgs);
base.OnTextChanged(eventArgs);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With