-
January 31st, 2011, 04:38 AM
#1
Changing color of selected Button in a group
Hi,
Imagine we have a group of buttons. How it is possible to change the color of a button when it is clicked and if another button of same group is clicked the last one turns back to normal and new one which is clicked changes its color?!
Thanks.
-
January 31st, 2011, 11:16 AM
#2
Re: Changing color of selected Button in a group
The easiest way? When a button is clicked, change all of the colors of the buttons back to the default color, then change the color of the clicked button.
===============================
My Blog
-
January 31st, 2011, 11:36 AM
#3
Re: Changing color of selected Button in a group
It will be do able like that, but when you have lots of groups and buttons it will be pain in the ***, I am looking for a more general way.
-
January 31st, 2011, 12:44 PM
#4
Re: Changing color of selected Button in a group
Originally Posted by Sean87
It will be do able like that, but when you have lots of groups and buttons it will be pain in the ***, I am looking for a more general way.
The "more general way" that you are looking for is called a loop. Add all of the buttons to a collection and just iterate through them.
Code:
void button_Click( object sender, EventArgs e )
{
foreach( Button b in SomeButtonCollection )
{
b.BackColor = SystemColors.Control
}
((Button)sender).BackColor = SomeOtherColor;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|