Reputation: 25
How to change panels color on button_click event? Below is code snippet, I want to change color of panel1
when I click on Clear button.
private void buttClear_Click(object sender, EventArgs e)
{
txtPntX.Text = "";
txtPntY.Text = "";
txtSrtPtX.Text = "";
txtSrtPtY.Text = "";
txtEndPtX.Text = "";
txtEndPtY.Text = "";
}
Upvotes: 0
Views: 1592
Reputation: 484
Why don´t just use:
private void buttClear_Click(object sender, EventArgs e)
{
txtPntX.Text = "";
txtPntY.Text = "";
txtSrtPtX.Text = "";
txtSrtPtY.Text = "";
txtEndPtX.Text = "";
txtEndPtY.Text = "";
panel1.BackColor = Color.Red; // < This one
}
Upvotes: 0
Reputation: 149
If you want to change a color every time the txtSrtPtX
textbox text changes, you need to add an event TextChanged
:
private void txtSrtPtX_TextChanged(object sender, EventArgs e)
{
panel1.BackColor = Color.Red;
}
The panel in your case will change color 6 times:
private void buttClear_Click(object sender, EventArgs e)
{
txtPntX.Text = ""; //1
txtPntY.Text = ""; //2
txtSrtPtX.Text = ""; //3
txtSrtPtY.Text = ""; //4
txtEndPtX.Text = ""; //5
txtEndPtY.Text = ""; //6
}
Upvotes: 0