Search and edit null labels in the form

时间:2016-10-20 19:03:16

标签: c# foreach

I was trying to create a simple like to-do list. When I click the button, it should, from another form, search for the null labels and fill in first one with the text which is written in the text box. This what I have reached so far but it doesn't work at all:

Form1 f = new Form1();  
public void writetext()
{
    foreach (Control x in f.Controls)
    {
        if (x is Label)
        {
               if (((Label)x).Text == "")
            {
                ((Label)x).Text = textBox1.Text;
            }                          
        }
    }
}      

0 个答案:

没有答案