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

解决方案 »

  1.   

    问题是,我把时间设为1500毫秒,也不快了,可是还是什么都没有;
    timer1.Enabled = true ;
    timer1.Interval = 1500;
      

  2.   

    你这个g.FillEllipse是放在什么地方,如果放在定时器的触发函数里肯定出不来啊,你要放在OnPaint函数里,因为Invalidate是导致窗口重绘。要能移动,而前面画的点消失,应该放在Onpaint函数里绘制,Timer只是改变绘制的位置。
      

  3.   

    是不是this.Invalidate ();不能再Timer里面调用,
    是的在OnPain()里面应该是可以,可是画图应该是触发某个按钮才动作的阿,不能以进来就运行巴
      

  4.   

    设置一个变量,按钮触发后,该变量为真,在OnPain()里面通过判断该变量决定运行情况。
      

  5.   

    不行,在OnPain()里面调用this.Invalidate ();整个背景闪得厉害,感觉死循环了。
      

  6.   

    那里调用Refresh(),在OnPain()里面还是很闪,在timer1里面添加,还是闪不出来。
      

  7.   

    你设置this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor,true);如果还闪,那就要双缓冲。不过你的刷新速度不快的话,应该不闪了。你要注意你的画图函数应该在OnPaint中,才能闪出来
      

  8.   

    g.FillEllipse (redBrush,(int)TemLoaX,(int)TemLoaY,PoiWid,PoiHig);
    this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor,true);
    this.Refresh();
    这样吗?
    在OnPain()函数里面,可是还是一闪一闪的,而且停止的时候都看不到小球!
      

  9.   

    看看是不是你要的效果,我机器上是不闪的(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();
            }
        }
    }
      

  10.   

    sadever(空之殇),谢谢,我回家了,刚来,这就试。
      

  11.   

    using System.Collections.Generic;
    这句有问题,找不到Generic命名空间啊?
    如果改成using System.Collections,这句:this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);会出错,不包含ControlStyles.OptimizedDoubleBuffer 的定义;