Going through every button?

Started by G_G, February 13, 2010, 01:19:39 pm

Previous topic - Next topic

G_G

February 13, 2010, 01:19:39 pm Last Edit: February 13, 2010, 03:55:10 pm by game_guy
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?

Blizzard

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. :/
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

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";
    }
}