# Change button color?

**URL:** <https://forum.kirupa.com/t/change-button-color/303299>\
**Category:** Uncategorized\
**Created:** [January 18, 2010, 12:59pm UTC](https://forum.kirupa.com/t/change-button-color/303299 "2010-01-18T12:59:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephsh](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@stephsh](https://forum.kirupa.com/u/stephsh)\
**Post date:** [January 18, 2010, 12:59pm UTC](https://forum.kirupa.com/t/change-button-color/303299/1 "2010-01-18T12:59:23Z")

</div>

I’ve spent ages trying to work this problem out… When I click on a button the background should change colour. If another button has already been clicked previously (btnSkillSelected = true) then this button should first be turned back transparent. This does not however happen, instead it stays light blue!

```php

// When a btn is checked the following method is executed
private void btnSkill_CheckedChanged(object sender, EventArgs e)
{
// If a btn has been enabled before
if (btnSkillSelected == false)
{
MessageBox("1st time a btn is selected!");
// save selected btnSkill
selectedSkillID = int.Parse(btnSkill.ID);
}
else
{
MessageBox("not the 1st time a btn is selected!");
// Find the previously selected btn
for (int i = 0; i < criterium.Length; i++)
{
if (btnSkill.ID == Convert.ToString(selectedSkillID))
{
// Disable the previously selected button
btnSkill.BackColor = System.Drawing.Color.Transparent;
btnSkill.Enabled = true;
}
}
}
// True for both methods:
// Show that a button has been enabled
btnSkillSelected = true;
// Change state of currently selected btn
btnSkill = (Button)sender;
selectedSkillID = int.Parse(btnSkill.ID); 
btnSkill.BackColor = System.Drawing.Color.LightBlue;
btnSkill.Enabled = false;
// Create side table
CreateTblCriterium(selectedSkillID);
}

```
