Skip to content

Handle Multiple Controls with index

Fox Freejack

Asked Oct 8, 2005, 8:39 PM EDT1 answer
Share
LinkedInX
Hi, I've been searching all day about this and found more or less... I have to handle a bunch of Controls (labels and listboxes) about 20-30 of them each. I don't want to program every one of them with individual code. for example: label[1].Location = new Location(x1,y1) listbox[1].Location = new Location(x2,y2); ... Thank you! Fox

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Try this:

    private void SomeMethod()

    {

    Code
    foreach(System.Windows.Forms.Control c1 in this.Controls)
    
    /*Where this.Controls can be replaced with this.panel1.Controls if in a panel
    or form1Instance.Controls is calling outside a form instance....
    */
    {

    if(c1 is System.Windows.Forms.Label)

    {

    c1.Text = "Hello World";

    }

    }

    }

    0