Chaos Project

Game Development => Sea of Code => Topic started by: G_G on February 13, 2010, 01:19:39 pm

Title: Going through every button?
Post by: G_G on February 13, 2010, 01:19:39 pm
Well as some of you may know there will be different themes for Cybele. I know how to change the image and color and everything for the buttons. My only problem is I have quite a few buttons and I dont want to have to type a line for every single one of them to just change a color.

Is it possible to have iterate through every button?
Title: Re: Going through every button?
Post by: Blizzard on February 14, 2010, 05:49:21 am
You could put them into an array in the form constructor. That's how I do it.
Of course, there's a way to iterate through all children controls of the form, but then you have to check the type (if it's a Button instance) and that seems kinda dirty. :/
Title: Re: Going through every button?
Post by: G_G on February 14, 2010, 12:02:40 pm
I havent tried this yet. Only because I'm re-installing c# express right now.
But I think this would work.
foreach (Control ctrl in this.Controls)
{
    if (ctrl is Button)
    {
        ctrl.Text = "Hello";
    }
}