Dynamic Button Loop
-
Hello, I'm trying to make a program where I modify properties of a lot of buttons. The names are sequential, like button1, button2, etc. all the way to button81. Buttons 82 through 90, though, I don't want to mess with--they have a different purpose. I can't remember how to do this and I definitely don't want to modify each one individually. Any pointers? Thanks for your time, Michael Fritzius
-
Hello, I'm trying to make a program where I modify properties of a lot of buttons. The names are sequential, like button1, button2, etc. all the way to button81. Buttons 82 through 90, though, I don't want to mess with--they have a different purpose. I can't remember how to do this and I definitely don't want to modify each one individually. Any pointers? Thanks for your time, Michael Fritzius
for(int i=1; i<91;i++) { this.Controls["button"+i].Text="this is button number "+i.ToString(); }
#region signature my articles #endregion
-
Hello, I'm trying to make a program where I modify properties of a lot of buttons. The names are sequential, like button1, button2, etc. all the way to button81. Buttons 82 through 90, though, I don't want to mess with--they have a different purpose. I can't remember how to do this and I definitely don't want to modify each one individually. Any pointers? Thanks for your time, Michael Fritzius
-
for(int i=1; i<91;i++) { this.Controls["button"+i].Text="this is button number "+i.ToString(); }
#region signature my articles #endregion
It would work fine, but he doesn't want to mess with buttons 82 through 90.
"I really like comments where I don't have to answer stupid questions" - stfx
-
It would work fine, but he doesn't want to mess with buttons 82 through 90.
"I really like comments where I don't have to answer stupid questions" - stfx
Oh I forgot then. Then it will look like this:
for(int i=1; i<82;i++) { this.Controls["button"+i].Text="this is button number "+i.ToString(); }
#region signature my articles #endregion
-
Oh I forgot then. Then it will look like this:
for(int i=1; i<82;i++) { this.Controls["button"+i].Text="this is button number "+i.ToString(); }
#region signature my articles #endregion
Could always throw in a switch/if block if there is a range within the loop he wants to skip :-D
"I really like comments where I don't have to answer stupid questions" - stfx
-
Could always throw in a switch/if block if there is a range within the loop he wants to skip :-D
"I really like comments where I don't have to answer stupid questions" - stfx
Look, if you want to skip a small portion of a loop, and an if statement, and continue:
for(int i=0; i<100; i++) {
if(i >= 82 && i <= 90) continue; this.Controls\[whatever\]...
}
My current favourite word is: Waffle Cheese is still good though.
-
Look, if you want to skip a small portion of a loop, and an if statement, and continue:
for(int i=0; i<100; i++) {
if(i >= 82 && i <= 90) continue; this.Controls\[whatever\]...
}
My current favourite word is: Waffle Cheese is still good though.
Yeah, there are alot of ways we could get creative with it :-D
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Yeah, there are alot of ways we could get creative with it :-D
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
You could do all sorts of things. I still like the idea of creating the buttons dynamically though. Of course then if you needed to change them, hmm.
My current favourite word is: Waffle Cheese is still good though.
-
Hello, I'm trying to make a program where I modify properties of a lot of buttons. The names are sequential, like button1, button2, etc. all the way to button81. Buttons 82 through 90, though, I don't want to mess with--they have a different purpose. I can't remember how to do this and I definitely don't want to modify each one individually. Any pointers? Thanks for your time, Michael Fritzius
Wow I haven't gotten the chance to come back and say thanks to everyone who gave answers. But I took the advice of the first person, which is what I needed, because I need to still modify the buttons during the program. Thanks to all! Michael Fritzius