Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to expose the Text property of a UserControl?
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2881409/text-property-in-a-usercontrol-in-c-sharp">Text property in a UserControl in C#</a> </p> </blockquote> <p>How do I mark the <code>Text</code> property of a <code>UserControl</code> as browsable?</p> <hr> <p>A .NET <a href="http://msdn.microsoft.com/en-us/library/97855yck.aspx" rel="nofollow noreferrer"><code>UserControl</code></a> class has a <a href="http://msdn.microsoft.com/en-us/library/y7k5hkke.aspx" rel="nofollow noreferrer"><code>Text</code></a> property.</p> <p>Unfortunately the <code>Text</code> property of a <code>UserControl</code> isn't <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx" rel="nofollow noreferrer"><strong><em>browsable</em></strong></a>:</p> <pre><code>// // // Returns: // The text associated with this control. [Bindable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public override string Text { get; set; } </code></pre> <p>In my <code>UserControl</code> I <em>want</em> to expose the <code>Text</code> property (i.e. make it "<em>browsable</em>") in the properties window. I tried blindly declaring it browsable:</p> <pre><code>[Browsable(true)] public override string Text { get; set; } </code></pre> <p>and now it appears in the properties window, except now it does nothing.</p> <p>I tried blindly calling <code>base.Text</code> to bring back the functionality:</p> <pre><code>[Browsable(true)] public override string Text { get {return base.Text;} set { base.Text = value; this.Invalidate(); } } </code></pre> <p>and now the property does function at design-time, but the property value is not persisted to the <code>Form.Designer.cs</code> and it's <code>InitalizeComponent</code> code.</p> <p>What is the <em>proper</em> way to expose the <code>UserControl</code> <code>Text</code> property so that it: </p> <ul> <li>is browsable in the properties window</li> <li>is functional</li> <li>is persisted in the form designer</li> </ul> <p><em>and, as a bonus</em>:</p> <ul> <li>know when it changes</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload