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

用GDI画点,然后用Timer让它移动,可是,移动后,之前的点不会消失;
用GDI画点,然后用Timer计算出下一个时刻的位置,使得它移动;
g.FillEllipse   (redBrush,(int)TemLoaX,(int)TemLoaY,PoiWid,PoiHig);
可是,移动后,之前的点不会消失;加上语句:this.Invalidate   ();屏幕上就闪不出来东西,是不是刷新太快,还是其他原因?


------解决方案--------------------
看看是不是你要的效果,我机器上是不闪的(VS2005)。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Timer
{
public partial class Form1 : Form
{
public int X;
public int Y;
public bool Draw;
public int wi;
public int he;
public Form1()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
this.X = 10;
this.Y = 10;
this.wi = 20;
this.he = 20;
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (Draw == true)
{
g.FillEllipse(new SolidBrush(Color.Blue), X, Y, wi, he);

}
}

private void timer1_Tick(object sender, EventArgs e)
{
if (this.X <= this.Width - 180) this.X += 20;
else this.X = 10;
this.Refresh();
}

private void button1_Click(object sender, EventArgs e)
{

this.timer1.Start();
this.Draw = true;
}

private void button2_Click(object sender, EventArgs e)
{
this.timer1.Stop();
}
}
}