如何在打开新的子表单时增加新表单的名称

时间:2014-02-15 04:05:40

标签: c# winforms parent-child mdiparent

How do you change the text in the Titlebar in Windows Forms?

当我打开一个新表格时,我希望它说“鲍勃,下次我点击新的并打开表格时应该说”Bob1“ 我尝试将TryParase()用于字符串,但不能正常工作。

private void newToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Form2 childform2 = new Form2();
        decimal childcount;
       childform2.MdiParent= this;
       string menuname;
       menuname = "untilted" + childcount.ToString();
        childform2.Text = menuname;
        childform2.Show();
        childcount++;

    }

1 个答案:

答案 0 :(得分:1)

您需要保持childcount的时间长于该方法。由于您在方法中声明它,因此每次运行此代码时它都会重置为0。在方法之外声明变量,如下所示:

int childcount=1;
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
   Form2 childform2 = new Form2();

   childform2.MdiParent= this;
   string menuname;
   menuname = "untilted" + childcount.ToString();
   childform2.Text = menuname;
   childform2.Show();
   childcount++;
}