Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting Form.Text in WinForms Form does not update the title

Tags:

c#

winforms

I have this piece of code in my routine but it doesnt seem to work:

public MainForm()
{
  InitializeComponent();
  this.Text = "Elvis " + AssemblyVersion;
}

In my designer I had set the form title to "Elvis". I see that the AssemblyVersion info gets added to the text properly but the title doesnt get updated at all. I've tried refresh, invalidate etc, but nothing works. Any idea how I can update the title at runtime?

I am using .NET 3.5 and VS 2008.

thanks

like image 560
Murlex Avatar asked Nov 23 '10 19:11

Murlex


People also ask

How do I change the title of a Windows form?

To rename a form, you can open the form and click the title to edit it, it changes the form name as well.

Which property of a Windows form should you change to set the text shown on the title bar?

You can change the text in the titlebar in Windows Forms by using the Text property.

How do I refresh winform?

You can use the Form. Invalidate(); or Form. Refresh(); methods.

How do I change the title of a form in Visual Studio?

Right-click Form1. vb in the Solution Explorer window (the window above the Properties window). Choose Rename from the context menu that appears.


3 Answers

This generally works just fine. Setting the Text property of a Form will change the title of the window. So can you post more code? It's possible your Text property is later getting overwritten without you realizing it.

like image 108
Matt Greer Avatar answered Sep 19 '22 03:09

Matt Greer


I had the same issue and it was because of the Initialize components function that is changing the form's header, if you set the header using the constructor, it will be overwritten with the InitializeComponents function value. Solution: remove the form's property set in the InitializeComponent function.

Best regards, Chen

like image 25
Chen Avatar answered Sep 20 '22 03:09

Chen


Try to put this

this.Text = "Elvis " + AssemblyVersion; 

on the onload event

like image 22
asmodeo Avatar answered Sep 17 '22 03:09

asmodeo