日期:2014-05-18  浏览次数:21027 次

用C#写了个俄罗斯方块,图像放在panel 中,在panel中绘制图,结果图像闪烁,急求解决
private void panel1_Paint(object sender , PaintEventArgs e)
  {// Create image.
  // Bitmap bmp = new Bitmap(240, 360);
  // PaintEventArgs e = bmp.CreateGraphics();
   
  this.Change();
  if (ChangTiaoHent.y == 17)
  {
  }
  if (Xianshi[0, 6] == true)
  {
  Init();
  }
  if (Yunxing ==true)
  {
  for (int i = 0; i < 18; i++)
  {
  for (int j = 0; j < 12; j++)
  {
  if (Xianshi[i, j] == true )
  {
  Image newImage = Image.FromFile("KK.png");

  // Create Point for upper-left corner of image.
  Point ulCorner = new Point(j*20 , i*20);

  // Draw image to screen.
  e.Graphics.DrawImage(newImage, ulCorner);
  Console.Write(i.ToString() + ";" + j.ToString());
  }
  }
  }
  if (Yunxing == true && Xing == 1)
  {
  if (ChangTiaoHent.y == 17)
  {
  Image newImage = Image.FromFile("KK.png"); Point ulCorner = new Point(100, 100);
  e.Graphics.DrawImage(newImage, new Point(20 * ChangTiaoHent.x, 20 * ChangTiaoHent.y));
  Xianshi[ChangTiaoHent.y, ChangTiaoHent.x] = true;
  if (ChangTiaoHent.y >= 1) e.Graphics.DrawImage(newImage, new Point(20 * ChangTiaoHent.x, 20 * (ChangTiaoHent.y - 1)));
  if (ChangTiaoHent.y >= 2) e.Graphics.DrawImage(newImage, new Point(20 * ChangTiaoHent.x, 20 * (ChangTiaoHent.y - 2)));
  if (ChangTiaoHent.y >= 3) e.Graphics.DrawImage(newImage, new Point(20 * ChangTiaoHent.x, 20 * (ChangTiaoHent.y - 3)));
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y - 1, ChangTiaoHent.x] = true;
  if (ChangTiaoHent.y >= 2) Xianshi[ChangTiaoHent.y - 2, ChangTiaoHent.x] = true;
  if (ChangTiaoHent.y >= 3) Xianshi[ChangTiaoHent.y - 3, ChangTiaoHent.x] = true; this.ChongG();
  }
  else
  {
  if ((ChangTiaoHent.y <= 16) && (!Xianshi[ChangTiaoHent.y + 1, ChangTiaoHent.x] == true))
  {

  Image newImage = Image.FromFile("KK.png"); Point ulCorner = new Point(100, 100);

  if (ChangTiaoHent.y >= 0) e.Graphics.DrawImage(newImage, new Point(20 * ChangTiaoHent.x, 20 * ChangTiaoHent.y));

  if (ChangTiaoHent.y >= 1) e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x), 20 * (ChangTiaoHent.y - 1)));

  if (ChangTiaoHent.y >= 2) e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x), 20 * (ChangTiaoHent.y - 2)));

  if (ChangTiaoHent.y >= 3) e.Graphics.DrawImage(newImage, n