Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Show Control.Text in VisualStudio Designer

13 like 0 dislike
I'm using VisualStudio 2005 and I want to set the text of a control on a form. For various reasons this should not be done in the VisualStudio Designer. I could write the code as follows:

   public Form1( )
    {
        InitializeComponent( );
        button1.Text = "Test";
    }

But now I don't see the text in the designer, the button is empty (or has the default text of "button1"). Is there a way to set the text of a control outside the designer and see the text in Visual Studio Designer? The text should not be editable, it must only be visible. This would be really nice, because it would be possible to use constants for frequently used phrases and still see them in the designer to adjust the ui.
asked 2 years ago by SeO (39,810 points)

2 Answers

2 like 0 dislike
 
Best answer
1
   

It's a bit hacky, but you could subclass the control you want and override the Text property:

public class MyTest : Button
{
    public override string Text
    {
        get
        {
            return @"test";
        }
        set
        {
        }
    }
}

This shows up in the designer, but when you try and change it Visual Studio just ignores you. You probably want to do something other than just return a hardcoded string literal, but I'm sure you get the idea :-)
answered 2 years ago by BloggeR (179,550 points)
0 like 0 dislike
It's a bit hacky, but you could subclass the control you want and override the Text property:

public class MyTest : Button
{
    public override string Text
    {
        get
        {
            return @"test";
        }
        set
        {
        }
    }
}

This shows up in the designer, but when you try and change it Visual Studio just ignores you. You probably want to do something other than just return a hardcoded string literal, but I'm sure you get the idea :-)
answered 2 years ago by biswaskeran (70,430 points)

Related questions

9 like 0 dislike
0 answers
9 like 0 dislike
1 answer
asked 2 years ago by eagles11 (179,830 points)