我现在用的是timer+label来实现的,但是就是感觉很抖,还有点闪烁的感觉
哪位能给个控件从A点平滑移动到B点的例子啊
谢谢

解决方案 »

  1.   

    没想到更好的方法。
    个人体会是,lable显示效果不理想,有时刷新容易出问题,换个别的吧,比如panel啥的。闪烁的话DoubleBuffer之类的设置一下应该有改善。
      

  2.   

    不要用time,label
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;namespace WindowsApplication73
    {
        public partial class Form1 : Form
        {
            Bitmap OrgBmp = null;
            int PosX = 0;
            Thread T = null;        delegate void DrawForm(Bitmap CacheBmp);        public Form1()
            {
                InitializeComponent();            OrgBmp = new Bitmap(this.Width, this.Height);
                Graphics G = Graphics.FromImage(OrgBmp);
                G.FillRectangle(new SolidBrush(this.BackColor), this.Bounds);
                G.Dispose();            T = new Thread(new ThreadStart(Run));
                T.IsBackground = true;
                T.Start();        }        void Run()
            {
                Bitmap CacheBmp = null;
                Graphics G = null;            try
                {
                    while (true)
                    {
                        if (++PosX > this.Width)
                            PosX = 0;
                        CacheBmp = new Bitmap(OrgBmp);
                        G = Graphics.FromImage(CacheBmp);
                        G.DrawString("ABCDEFG12345", new Font("宋体", 10), Brushes.Green, new PointF(PosX, 0));
                        if (!this.IsDisposed && this.IsHandleCreated)
                            this.Invoke(new DrawForm(DoDrawForm), new Object[] { CacheBmp });
                    }
                }
                catch
                {
                }
                finally
                {
                    if (G != null)
                        G.Dispose();
                    if (CacheBmp != null)
                    {
                        CacheBmp.Dispose();
                        GC.Collect();
                    }
                }
            }        void DoDrawForm(Bitmap CacheBmp)
            {
                Graphics G = null;            try
                {
                    G = this.CreateGraphics();
                    G.DrawImage(CacheBmp, new Point(0, 0));
                }
                finally
                {
                    if (G != null)
                        G.Dispose();
                    GC.Collect();
                }
            }
        }
    }
      

  3.   


                BufferedGraphicsContext current = BufferedGraphicsManager.Current; //(1)
                BufferedGraphics bg;
                bg = current.Allocate(this.CreateGraphics(),this.DisplayRectangle); //(2)
                Graphics g = bg.Graphics;//(3)
                //随机 宽400 高400
     
                System.Random rnd = new Random();
                int x,y,w,h,r,i;
                for (i = 0; i < 10000; i++)
                {
                    x = rnd.Next(400);
                    y = rnd.Next(400);
                    r = rnd.Next(20);
                    w = rnd.Next(10);
                    h = rnd.Next(10);
                    g.DrawEllipse(Pens.Blue, x, y, w, h);
                }
                bg.Render();//(4)
                //bg.Render(this.CreateGraphics());
                bg.Dispose();//(5)
         自己开辟一个缓冲区(如一个不显示的Bitmap对象),在其中绘制完成后,再一次性显示。
    完整代码如下:
                Bitmap bt = new Bitmap(400, 400);
                Graphics bg = Graphics.FromImage(bt);
                System.Random rnd = new Random();
                int x, y, w, h, r, i;
                for (i = 0; i < 10000; i++)
                {
                    x = rnd.Next(400);
                    y = rnd.Next(400);
                    r = rnd.Next(20);
                    w = rnd.Next(10);
                    h = rnd.Next(10);
                    bg.DrawEllipse(Pens.Blue, x, y, w, h);
     
                }
                this.CreateGraphics().DrawImage(bt, new Point(0, 0));
    本文来源于网络小筑 http://www.iwebtrados.com.cn/ , 原文地址:http://www.iwebtrados.com.cn/post/41.html 这段代码就是用双缓存画10000个小圆,能稍微说下这两节代码的作用吗?
      

  4.   

    上面的两段代码是不是实现相同的功能,只是第一段直接在内存上创建Graphics对象,这才是用了双缓存啊?
    用缓存处理图片,只是在窗口刷新一次的过程中,让所有图元同时显示到窗口上,但是怎么保证图片是平滑的移动呢?