views:

25

answers:

1

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.

+1  A: 

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 :-)

Steven Robbins