private void timer1_Tick(object sender, EventArgs e) { Random ram = new Random(); Button btn1 = new Button(); btn1.Width = 65; btn1.Height = 45; btn1.Text = "X"; btn1.Click += new EventHandler(button3_Click); //------------------------------------------------------ mycolumn = ram.Next(0, 5); myrow = ram.Next(0, 5); Hesap(mycolumn, myrow, btn1); } public void Hesap(int a, int b, Button btn1) { if (tableLayoutPanel1.Controls.Count < 36) { if (myarray[a, b] == null) { myarray[a, b] = "have"; tableLayoutPanel1.Controls.Add(btn1, a, B); } else if (myarray[a, b] == "have") { // Control mycont = new Control(tableLayoutPanel1.Controls.ToString()); Control c = null; myarray[a, b] = null; tableLayoutPanel1.Controls.Add(btn1, a, B); c = this.tableLayoutPanel1.GetControlFromPosition(a, B); tableLayoutPanel1.GetCellPosition(c); if (c != null) { this.tableLayoutPanel1.Controls.Remove(c); c = null; } } } } private void button3_Click(object sender, EventArgs e) { ((Button)sender).Dispose(); } }}