//button event handler for the four button private void btnEVENT_Click(object sender, EventArgs e) { Round_Button button = sender as Round_Button; if (button != null) { // now you know the button that was clicked switch ((int)button.Tag) { case 0: // First Button Clicked M1Count++; if (M1Count == 8) { M1Count = 0; } button.BackColor = clrArray[M1Count]; Marble1 = clrChar[M1Count]; break; case 1: // Second Button Clicked M2Count++; if (M2Count == 8) { M2Count = 0; } button.BackColor = clrArray[M2Count]; Marble2 = clrChar[M2Count]; break; case 2: //third button clicked M3Count++; if (M3Count == 8) { M3Count = 0; } button.BackColor = clrArray[M3Count]; Marble3 = clrChar[M3Count]; break; case 3: //fourth button clicked M4Count++; if (M4Count == 8) { M4Count = 0; } button.BackColor = clrArray[M4Count]; Marble4 = clrChar[M4Count]; break; } } }
// dynamically creating a hard level board design when user hits hard button private void btnHard_Click(object sender, EventArgs e) { L.startTimer(); Mode = "Hard"; currentButton = 0; currentPin = 0; for (int r = 0; r < 8; r++) { //Create One Row of Round color Buttons for (int i = 0; i < 4; i++) { Round_Button button = new Round_Button(); button.Location = new Point(15 + (80 * i), 5 + (65 * r)); button.Size = new Size(50, 50); //sets buttons borderless appearance button.TabStop = false; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.DarkGray; //sets the event of color buttons to the color event handler! button.Click += new EventHandler(btnEVENT_Click); //give button a tag switching which event handler path it takes depends on which column button.Tag = i; if (r != 0) { button.Visible = false; } button.Name = "btn" + Convert.ToString(currentButton); currentButton++; this.Controls.Add(button); } //Create 4 Pin Buttons for (int i = 0; i < 4; i++) { Round_Button button = new Round_Button(); button.Location = new Point(325 + (30 * i), 10 + (70 * r)); button.Size = new Size(20, 20); button.TabStop = false; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.Enabled = false; button.Visible = false; button.Name = "pin" + Convert.ToString(currentPin); currentPin++; this.Controls.Add(button); } } currentPin = 0; btnEasy.Enabled = false; btnMedium.Enabled = false; btnHard.Enabled = false; }