【问题标题】:How to increase the name of a new form when opening a new child form打开新的子表单时如何增加新表单的名称
【发布时间】:2014-03-14 15:11:36
【问题描述】:

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

当我打开一个新表单时,我希望它显示“Bob,下次我单击新建并打开一个表单时,它应该显示“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++;

    }

【问题讨论】:

    标签: c# winforms parent-child mdiparent


    【解决方案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++;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-06
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2011-12-21
      • 2010-12-20
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      相关资源
      最近更新 更多