u/Jonathan_Palmer

▲ 0 r/csharp

So my problem is that I am trying to change B_Class between true and false depending on the button. The button changes color correctly. However the boolean variable remains set to true regardless. As far as I understand this should be working, and it was before I put it inside a method rather than repeating the code 7 times. Any help would be greatly appreciated.

using System.Security.Cryptography;

namespace GodBreakers_RandomTangles

{

`public partial class GodBreakers_RunGenerator : Form`

`{`

	`bool B_Class = true;`

	`bool B_Ability = true;`

	`bool B_RandomPlanetOrder = true;`

	`bool B_Tangle1 = true;`

	`bool B_Tangle2 = true;`

	`bool B_Tangle3 = true;`

	`bool B_Tangle4 = true;`

	`bool B_Tangle5 = true;`



	`public GodBreakers_RunGenerator ( )`

	`{`

		`InitializeComponent ( );`

	`}`



	`private void tableLayoutPanel1_Paint ( object sender, PaintEventArgs e )`

	`{`



	`}`



	`private void comboBox4_SelectedIndexChanged ( object sender, EventArgs e )`

	`{`



	`}`



	`private void BTN_GenerateRun_Click ( object sender, EventArgs e )`

	`{`

		[`MessageBox.Show`](http://MessageBox.Show) `( B_Class.ToString ( ) );`

		`if ( B_Class )`

		`{`

CB_Class.SelectedIndex = RandomNumberGenerator.GetInt32 ( 0, CB_Class.Items.Count );

		`}`





	`}`



	`private void BTN_Tangle1_Click ( object sender, EventArgs e )`

	`{`

		`Set_Button(BTN_Tangle1, B_Tangle1 );`

	`}`



	`private void BTN_Class_Click ( object sender, EventArgs e )`

	`{`

		`Set_Button ( BTN_Class, B_Class );`

	`}`



	`void Set_Button(Button button, bool B_Active)`

	`{`

		`if ( button.BackColor ==` [`Color.Red`](http://Color.Red) `)`

		`{`

button.BackColor = Color.Lime;

B_Active = true;

		`}`



		`else`

		`{`

button.BackColor = Color.Red;

B_Active = false;

		`}`

	`}`

`}`

}

reddit.com
u/Jonathan_Palmer — 2 months ago