miladel
Member
- Joined
- Aug 16, 2020
- Messages
- 14
- Programming Experience
- Beginner
Dear all,
Some thing went wrong with my buttons backcolor when I want to change it with Click. with the code below every thing is fine, if i press the button1 it turn to green and butten2 turns to gray and vice versa. the problem is that when i put both of them in a panel, only the panels backcolor change and nothing else happens. could anyone please give me some solution about this?
thanks.
Some thing went wrong with my buttons backcolor when I want to change it with Click. with the code below every thing is fine, if i press the button1 it turn to green and butten2 turns to gray and vice versa. the problem is that when i put both of them in a panel, only the panels backcolor change and nothing else happens. could anyone please give me some solution about this?
thanks.
C#:
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void changeBackColor(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c.Equals(sender))
c.BackColor = Color.LightGreen;
else
c.BackColor = Color.LightGray;
}
}
private void Button1_Click(object sender, EventArgs e)
{
changeBackColor(sender, null);
}
private void Button2_Click(object sender, EventArgs e)
{
changeBackColor(sender, null);
}
}
}