tags:

views:

31

answers:

1

hi

i have 25 button's in my form button1..button2......button25

i need to load image only from button1 to button8 (in any loop)

how i can do it ?

thank's in advance

+1  A: 

this is most simple code, you could use regex, linq etc. insted of this way

private void SetImages(Control c)
{
    foreach (Control curr in c.Controls)
    {
        if (curr.HasChildren) // for searching buttons in some containers
            SetImages(curr);

        if (curr.Name.Contains("button"))
        {
            int num = int.Parse(curr.Name.Replace("button", string.Empty));
            if (num >= 0 && num <= 8)
            {
                // Add code thats sets the image for a button ((Button)c).XXXX
            }
        }
    }
}

usage

SetImages(Controls);
Sebastian Brózda