setting Form.Text in WinForms Form does not update the title
Asked Answered
G

4

10

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

Geodesic answered 23/11, 2010 at 19:11 Comment(2)
Make sure you are running the freshly builded executable...Nena
Could you post a short but complete program that reproduces the issue?Blat
N
17

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.

Nalepka answered 23/11, 2010 at 19:16 Comment(2)
Yes, indeed!! I was using a third party library that was reverting for some strange reason to the original title whenever I changed the title. Thanks!!Geodesic
I have a similar problem, I hooked into the TextChanged event to see if any other component is using the Forms Text Property - its not. It works in one Setup Method (User) but not in the other Setup(admin). Refreshing/Update/Invalidate wont do the trick, only resizing the form brings up the desired Text. Only soultion I have found so far is resizing by code: Me.Size = New Size(Me.Size.Width + 1, Me.Size.Height)Fructidor
P
2

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

Peach answered 10/9, 2013 at 20:50 Comment(0)
A
1

Try to put this

this.Text = "Elvis " + AssemblyVersion; 

on the onload event

Audiphone answered 23/11, 2010 at 19:19 Comment(0)
C
0

In my case, I had a to change the TextBox.Text not the Text itself.

someElement.TextBox.Text = "Whatever The Text Is";
Careful answered 15/7 at 20:0 Comment(2)
OP was specifically trying to set the window caption (which he called "title"), not a textbox.Housum
I see thanks for the clarification.Careful

© 2022 - 2024 — McMap. All rights reserved.