views:

16

answers:

2

Hi

I have something that looks like this

        H1    H2
CHK1    N1    D1
CHK2    N2    D2
CHK3    N3    D3
CHKN    NN    DN


        1      2
 3      4      5
 6      7      8
 9      10     11

// control positions if you had a counter counting with the foreach loop.

So H1 & H2 are just some labels, Chk is checkboxes and N & D are labels. I generate this table sort of looking thing dynamically.

Now I want to resize some of the labels dynamically. I want to find all the N1,N2,N3,NN labels and resize them.

So I am not sure how to do this.

First I found all controls

    foreach (Control c in panel.Controls)
    {
        if (c.GetType() == typeof(Label))
        {


        }


    }

Now I am not sure how to grab those N ones. Like N1 is Control 4, N2 is control 7 and N3 is control 10.

So at first I tried to just get all the even controls but I quickly realized that the N1 controls go even then odd.

So that will not work. So I am not sure how to write something to get these controls I want.

A: 

Can you keep track of them when you create them? Store them in a list so you can reference them later?

Matt Breckon
+1  A: 

Most controls have a Tag property., You can set all the tags of those controls you require to a value you wish, and then in the itteration, you can check for the tag value.

foreach (Control c in Controls)
if (c.Tag == "MyTag")
{
    //Do required actions
}

You also might think about a recursive function, if any of these controls are in container controls.

astander
I like this way. I came up a way of using (count % 3 == 1) and this works expect this gets for some reason the D column not N column so not sure what went wrong. It should give me the N column so maybe I did something else wrong but I like this way better it is safer. If some reason I flipped the columns around I would not have to change my code. The only thing that you have to do is c.Tag.Tostring() since tag is an object.
chobo2