首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

用C#写了个俄罗斯方块,图像放在panel 中,在panel中绘制图,结果图像闪烁,求解决,该如何解决

2012-03-24 
用C#写了个俄罗斯方块,图像放在panel 中,在panel中绘制图,结果图像闪烁,急求解决private void panel1_Pain

用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, new Point(20 * (ChangTiaoHent.x), 20 * (ChangTiaoHent.y - 3)));
  ++ChangTiaoHent.y;


  }
  else
  {
  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();


  }
  }
  }
  if ((Yunxing ==true)&&(Xing == 2))
  {
  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 + 1), 20 * (ChangTiaoHent.y)));
  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 2), 20 * (ChangTiaoHent.y)));
  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 3), 20 * (ChangTiaoHent.y)));
  }
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 1] = true;
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 2] = true;
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 3] = true; this.ChongG();
  }
  else
  {
  bool cece = true;
  cece = (ChangTiaoHent.y <= 16) && (!Xianshi[ChangTiaoHent.y + 1, ChangTiaoHent.x]) && (!Xianshi[ChangTiaoHent.y + 1, ChangTiaoHent.x + 1]);
  if ((cece && (!Xianshi[ChangTiaoHent.y + 1, ChangTiaoHent.x + 2]) && (!Xianshi[ChangTiaoHent.y + 1, ChangTiaoHent.x + 3]) == true))
  {

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

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


  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 1), 20 * (ChangTiaoHent.y)));

  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 2), 20 * (ChangTiaoHent.y)));

  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 3), 20 * (ChangTiaoHent.y)));


  ++ChangTiaoHent.y;
  }
  else
  {
  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 + 1), 20 * (ChangTiaoHent.y)));
  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 2), 20 * (ChangTiaoHent.y)));
  e.Graphics.DrawImage(newImage, new Point(20 * (ChangTiaoHent.x + 3), 20 * (ChangTiaoHent.y)));
  }
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 1] = true;
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 2] = true;
  if (ChangTiaoHent.y >= 1) Xianshi[ChangTiaoHent.y, ChangTiaoHent.x + 3] = true; this.ChongG();


  }
  }
  }
  e.Dispose();

  }


[解决办法]
double buffer

热点排行