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();
}
}
}
gardiann gardiannPosted Feb 28, 2011, 12:40 PM
Bryian TanPosted Feb 27, 2011, 11:08 PM
Try replace these line
with
if (myarray[a, b] == null)
{
myarray[a, b] = "have";
Control c = null;
c = this.tableLayoutPanel1.GetControlFromPosition(a, b);
if (c == null)
{
tableLayoutPanel1.Controls.Add(btn1, a, b);
}
}