private void MyButton_Click(object sender, EventArgs e) { if (button1.Enabled == true) { return; } Mybutton b1 = (Mybutton)(sender); ChangColor(b1.x, b1.y); ChangColor(b1.x - 1, b1.y); ChangColor(b1.x + 1, b1.y); ChangColor(b1.x, b1.y - 1); ChangColor(b1.x, b1.y + 1); if (Successed()) { MessageBox.Show("您已胜出"); for (int i = 0; i < H; i++) { for (int j = 0; j < H; j++) { this.b1[i, j].BackColor = Color.Red; } } InitializeMyButton(); button3.Enabled = false; } button3.Enabled = true; }
void ReleaseDesignerOutlets() { if (Mybutton != null) { Mybutton.Dispose(); Mybutton = null; } if (Wview != null) { Wview.Dispose(); Wview = null; } }
public void CreateMyButton(int Han, int Lie) { RemoveMyButton(); for (int i = 0; i < Han; i++) { for (int j = 0; j < Lie; j++) { b1[i, j] = new Mybutton(); b1[i, j].x = i; b1[i, j].y = j; panel1.Controls.Add(b1[i, j]); b1[i, j].Width = panel1.Width / Lie; b1[i, j].Height = panel1.Height / Han; b1[i, j].BackColor = Color.Red; b1[i, j].Left = panel1.Width / Lie * j; b1[i, j].Top = panel1.Height / Han * i; b1[i, j].Click += new EventHandler(MyButton_Click); } } button3.Enabled = false; H = Han; L = Lie; }