Итак, я играю в шахматы (на доске 64 кнопки с одним и тем же отправителем), и после того, как он нажал вторую кнопку, если ход разрешен, он установит фоновое изображение первой кнопки на ноль иот второго к первому:
public void button_click(object sender, EventArgs e)
{
if (partOfTurn == false)
{
for (int x = 0; x <= 7; x++)
{
for (int y = 0; y <= 7; y++)
{
if (Buttons[x, y] == ((Button)sender))
{
Ax = x;
Ay = y;
}
}
}
place_holder.BackgroundImage = ((Button)sender).BackgroundImage;
partOfTurn = true;
}
else if (partOfTurn == true)
{
for (int x = 0; x <= 7; x++)
{
for (int y = 0; y <= 7; y++)
{
if (Buttons[x, y] == ((Button)sender))
{
Bx = x;
By = y;
}
}
}
click();
partOfTurn = false;
}
void click()
{
if (turn == true)
{
if (place_holder.BackgroundImage == Properties.Resources.White_Pown)
{
if (Bx == Ax + 1 && By == Ay + 1 || Bx == Ax - 1 && By == Ay + 1)
{
if (((Button)sender).BackgroundImage == Properties.Resources.Black_Pown||
((Button)sender).BackgroundImage == Properties.Resources.Black_Rook||
((Button)sender).BackgroundImage == Properties.Resources.Black_Knight||
((Button)sender).BackgroundImage == Properties.Resources.Black_Bishop||
((Button)sender).BackgroundImage == Properties.Resources.Black_Queen||
((Button)sender).BackgroundImage == Properties.Resources.Black_King)
{
//set the background image of the first to null and of the other button to the first.
}
}
}
}
}
}
Но для этого мне нужно использовать отправителя (кнопки) второго, а также первого, чтобы очистить его.
Я пыталсячтобы обойти это и сохранить кнопку фона на заполнителе, чтобы я мог видеть, что было на кнопке, которая была нажата, но мне все еще нужно очистить первую кнопку
Есть идеи?