假设已知其实点POINT1,当鼠标在窗体移动时,如何在POINT1和鼠标当前坐标间画一条直线,当鼠标 移动时,连接POINT1和当前坐标,前一个线则擦除,视觉效果就是始终在POINT1和鼠标当前坐标间有一根线

解决方案 »

  1.   

    注意,背景是一个PICTURE,擦除原来的线时不能破坏背景图片
      

  2.   

    首先,从point到前一个点在用反色重绘一次,消除上条线,再从point到当前点绘制一次就可以。
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            Point startpoint = new Point(0, 0);
            Point endpoint;
            public Form2()
            {
                InitializeComponent();
                this.DoubleBuffered = true;
            }        private void Form2_MouseMove(object sender, MouseEventArgs e)
            {
                this.endpoint = new Point(e.X, e.Y);
                this.Invalidate();
            }        private void Form2_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawLine(Pens.Red, this.startpoint, this.endpoint);
            }
        }
    }
      

  4.   

            Point startpoint = new Point(0, 0);
            Point endpoint;
            public Form2()
            {
                InitializeComponent();
                this.DoubleBuffered = true;
            }        private void Form2_MouseMove(object sender, MouseEventArgs e)
            {
                this.endpoint = new Point(e.X, e.Y);
                this.Invalidate();
            }        //在窗体需要重绘的时候执行绘制直线方法
            private void Form2_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawLine(Pens.Red, this.startpoint, this.endpoint);
                //绘图.绘制直线       (红色画笔,起点坐标,终点坐标)
            }+1分全部都是3楼的~~~~~郁闷,来晚了,今天不玩了,每次都是来晚~~~~