Click here to Skip to main content
Click here to Skip to main content

Tagged as

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

, 14 Jun 2012
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

OriginalGriff
CEO
Wales Wales
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?
Follow on   Google+

Comments and Discussions

 
GeneralThanks PinmemberAshraf Sabry19-Jan-13 8:58 
GeneralSimple but... Pinmemberdb7uk14-Jun-12 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 14 Jun 2012
Article Copyright 2012 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid