使用鼠标屏幕交互绘图是经常在开发中使用, 下面以画线为例说明一下实现方法。 public partial class Form1 : Form { Boolean bHaveMouse; Point ptOriginal = new Point(); Point ptLast = new Point(); // Called when the left mouse button is pressed. public void MyMouseDown(Object sender, MouseEventArgs e) { // Make a note that we "have the mouse". bHaveMouse = true; // Store the "starting point" for this rubber-band rectangle. ptOriginal.X = e.X; ptOriginal.Y = e.Y; // Special value lets us know that no previous // rectangle needs to be erased. ptLast.X = -1; ptLast.Y = -1; } // Convert and normalize the points and draw the reversible frame. private void MyDrawReversibleLine(Point p1, Point p2) { // Convert the points to screen coordinates. p1 = PointToScreen(p1); p2 = PointToScreen(p2); ControlPaint.DrawReversibleLine(p1, p2, Color.Red); } // Called when the left mouse button is released. public void MyMouseUp(Object sender, MouseEventArgs e) { // Set internal flag to know we no longer "have the mouse". bHaveMouse = false; // If we have drawn previously, draw again in that spot // to remove the lines. if (ptLast.X != -1) { Point ptCurrent = new Point(e.X, e.Y); } Graphics g = this.CreateGraphics(); Pen pen = new Pen(System.Drawing.Color.Black); g.DrawLine(pen, ptOriginal, ptLast); pen.Dispose(); g.Dispose(); // Set flags to know that there is no "previous" line to reverse. ptLast.X = -1; ptLast.Y = -1; ptOriginal.X = -1; ptOriginal.Y = -1; } // Called when the mouse is moved. public void MyMouseMove(Object sender, MouseEventArgs e) { Point ptCurrent = new Point(e.X, e.Y); // If we "have the mouse", then we draw our lines. if (bHaveMouse) { // If we have drawn previously, draw again in // that spot to remove the lines. if (ptLast.X != -1) { MyDrawReversibleLine(ptOriginal, ptLast); } // Update last point. ptLast = ptCurrent; // Draw new lines. MyDrawReversibleLine(ptOriginal, ptCurrent); } } // Set up delegates for mouse events. protected override void OnLoad(System.EventArgs e) { this.Width = 800; this.Height = 600; MouseDown += new MouseEventHandler(MyMouseDown); MouseUp += new MouseEventHandler(MyMouseUp); MouseMove += new MouseEventHandler(MyMouseMove); bHaveMouse = false; } } 参考资料: