我正在使用 Visual Studio 创建一个程序。到目前为止,它只有一个带有按钮的窗口。
在 Form1.Designer.cs 中,它初始化窗口:
namespace Test
{
    private void InitializeComponent()
    {
        // I took out everything else, it isn't needed.
        // 
        // formMain
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.ControlLightLight;
        this.ClientSize = new System.Drawing.Size(624, 442);
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.Name = "formMain";
        this.Text = "Program Name";
        this.Load += new System.EventHandler(this.formMain_Load);
        this.menuBar.ResumeLayout(false);
        this.menuBar.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }
}
在 Form1.cs 中:
    private void button1_Click(object sender, EventArgs e)
    {
        formMain.ActiveForm.Text = formMain.ActiveForm.Text + " - Project Name";
    }
...但是在我单击按钮后它不会更改窗口文本。更改文本后我也尝试过formMain.ActiveForm.Refresh(),但这没有用。我一直在寻找解决方案,但我是 C# 新手。你们中有人对我有什么想法吗?