2014-02-15 53 views
-1

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

你需要保持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++; 
} 
+0

哦哇, 呃谢谢! – TangoIndiaMIke

相关问题