我现在要绘制一附图片,上面有一条线,一个点,其中线的位置在没有人工干预时是不动的,而点的坐标随时间的变化而变化,我怎样才能够将绘点与绘线的频次分开?即在绘图平面上只绘制坐标(或位置)变化的部分?

解决方案 »

  1.   

    调用Control的Invalidate(Rectangle)方法,其中Rectangle属性输入包含这个点,或线的一个矩形
      

  2.   

    首先感谢LorenLiu 帮忙,
    但上面的描述能否再详细些?我没有明白您的意思望能再指导一下!
    谢谢。
      

  3.   

    你看看下面的代码是否你所需求的?public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                mTimer = new Timer();
                mTimer.Interval = 500;
                mTimer.Tick += new EventHandler(mTimer_Tick);
                mTimer.Start();
            }        protected override void OnClosing(CancelEventArgs e)
            {
                base.OnClosing(e);
                mTimer.Stop();
                mTimer.Dispose();
            }        void mTimer_Tick(object sender, EventArgs e)
            {
                mPointLocation = new Point(mPointLocation.X + 1, mPointLocation.Y + 1);
                // 刷新点周围的矩形            
                this.Invalidate(new Rectangle(mPointLocation.X - 1, mPointLocation.Y - 1, 2, 2));
            }        Timer mTimer;
            Point mPointLocation = new Point(0, 0);        protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                e.Graphics.DrawLine(Pens.Black, new Point(10, 10), new Point(15, 100));
                e.Graphics.DrawRectangle(Pens.Red, mPointLocation.X, mPointLocation.Y, 1, 1);
            }
        }