简体   繁体   English

在WinForms表单中设置Form.Text不会更新标题

[英]setting Form.Text in WinForms Form does not update the title

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". 在我的设计师中,我将表单标题设置为“Elvis”。 I see that the AssemblyVersion info gets added to the text properly but the title doesnt get updated at all. 我看到AssemblyVersion信息被正确添加到文本中,但标题根本没有更新。 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. 我使用的是.NET 3.5和VS 2008。

thanks 谢谢

This generally works just fine. 这通常很好。 Setting the Text property of a Form will change the title of the window. 设置窗体的Text属性将更改窗口的标题。 So can you post more code? 你可以发布更多代码吗? It's possible your Text property is later getting overwritten without you realizing it. 你的Text属性可能会在没有意识到的情况下被覆盖。

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. 我遇到了同样的问题,因为Initialize组件函数正在更改表单的标题,如果使用构造函数设置标题,它将被InitializeComponents函数值覆盖。 Solution: remove the form's property set in the InitializeComponent function. 解决方案:删除InitializeComponent函数中的表单属性集。

Best regards, Chen 最诚挚的问候,陈

Try to put this 试着把它

this.Text = "Elvis " + AssemblyVersion; 

on the onload event 在onload事件上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM