【发布时间】:2013-08-19 23:13:25
【问题描述】:
我正在使用 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# 新手。大家有什么想法给我吗?
【问题讨论】:
-
“我把所有东西都拿出来了”是什么意思?您还取出了注册 button1_Click 事件处理程序的代码?不要编辑设计器生成的代码。
标签: c# visual-studio visual-studio-2012