我试图在graphicsPanel1_Paint
方法中编写一个 If 语句,其中只有在选择某个单选按钮并单击一个按钮时才会发生绘制。
这是我目前的代码:
private void graphicsPanel1_Paint(object sender, PaintEventArgs e)
{
for (int x = 0; x < mapSize.Width; x++)
{
for (int y = 0; y < mapSize.Height; y++)
{
Rectangle destRect = Rectangle.Empty;
destRect.X = x * tileSize.Width;
destRect.Y = y * tileSize.Height;
destRect.Size = tileSize;
destRect.X += graphicsPanel1.AutoScrollPosition.X;
destRect.Y += graphicsPanel1.AutoScrollPosition.Y;
Rectangle srcRect = Rectangle.Empty;
srcRect.X = map[x, y].X * tileSize.Width;
srcRect.Y = map[x, y].Y * tileSize.Height;
srcRect.Size = tileSize;
e.Graphics.DrawImage(Properties.Resources.colors, destRect, srcRect, GraphicsUnit.Pixel);
buttonUse.Click += buttonUse_Click;
if (radioButtonColor.Checked == true)
{
e.Graphics.DrawImage(Properties.Resources.colors, destRect, srcRect, GraphicsUnit.Pixel);
graphicsPanel1.Invalidate();
}
else if (radioButtonDesert.Checked == true)
{
e.Graphics.DrawImage(Properties.Resources.desert9x8x32x32, destRect, srcRect, GraphicsUnit.Pixel);
graphicsPanel1.Invalidate();
}
else if (radioButtonEarth.Checked == true)
{
e.Graphics.DrawImage(Properties.Resources._default, destRect, srcRect, GraphicsUnit.Pixel);
graphicsPanel1.Invalidate();
}
else if (radioButtonMagic.Checked == true)
{
e.Graphics.DrawImage(Properties.Resources.super4x4x64x64, destRect, srcRect, GraphicsUnit.Pixel);
graphicsPanel1.Invalidate();
}
e.Graphics.DrawRectangle(Pens.Black, destRect);
}
}
}
显然,这不起作用。
答案 0 :(得分:1)
您需要添加一个全局变量来检查单击的按钮(或切换状态),然后将事件处理程序添加到facebook 4.0.+ API
和if(empty($value["variable"])){
echo "variable is empty";
}
并使用此代码:
buttonUse
答案 1 :(得分:-1)
Click()是一个事件,因此您需要处理该事件,然后检查您的单选按钮。像
这样的东西buttonUse.Click()+= buttonUse_Click
void buttonUse_Click(object sender, RoutedEventArgs e)
{
if (radioButtonColor.Checked == true)
{
e.Graphics.DrawImage(Properties.Resources.colors, destRect, srcRect,GraphicsUnit.Pixel);
graphicsPanel1.Invalidate();
}
}