Table Layout Panel Problem :/

Feb 27 2011 3:51 PM
hi everyone i have a trouble this problem. i have 5x5 columns and rows i create a game to catch button. when the button create random cell location in the panel some button is re-write in to the cell and  i have to click 2 times for each cell :/.
how can i fix it? how can i delete if there is a button in the same location ??
-----------------------------------------------------------------------------------------------------my codes

int sayi = 0, mycolumn = 0, myrow = 0;
double süre = 00;
string[,] myarray = new string[6, 6];
      
 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();

}
}
}



Answers (2)