Search code examples
c#.netwinformstitlebar

Set Form.Text at designer time to a non-constant string


Instead of set the form.Text on VS property grid, I set the proper name in the application's assembly information so that everywhere I use the application's name or version I need to change in one place.

usually set the form.Text like this in the Form1_Load event:

private void Form1_Load(object sender, EventArgs e)
{
    this.Text = System.Windows.Forms.Application.ProductName;
}

so that I only see the application name as I set in the assembly information only at run-time, at designer time I have "form1" so to change this I decided to move the line:

this.Text = System.Windows.Forms.Application.ProductName;

To InitializeComponent() method, it worked, sort of. The title change but to this:

enter image description here

Is there any way to workaround this and get the proper name as I set in the assembly information rather than this Microsoft one?


Solution

  • The form you see during design-time is host under another environment than your actual solution. Hence why you are seeing this behavior.

    If you really want to view it during design-time, you should store the product name in a resource files or in the App.config as @Aniket pointed out.