using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; class ScribbleWithPath: Form { GraphicsPath path= new GraphicsPath(); bool bTracking; Point ptLast; public static void Main() { Application.Run(new ScribbleWithPath()); } protected override void OnMouseDown(MouseEventArgs mea) { if (mea.Button != MouseButtons.Left) return; ptLast = new Point(mea.X, mea.Y); bTracking = true; path.StartFigure(); } protected override void OnMouseMove(MouseEventArgs mea) { if (!bTracking) return; Point ptNew = new Point(mea.X, mea.Y); Graphics grfx = CreateGraphics(); grfx.DrawLine(new Pen(ForeColor), ptLast, ptNew); grfx.Dispose(); path.AddLine(ptLast, ptNew); ptLast = ptNew; } protected override void OnMouseUp(MouseEventArgs mea) { bTracking = false; } protected override void OnPaint(PaintEventArgs pea) { pea.Graphics.DrawPath(new Pen(ForeColor), path); } }