Often see others take a boxy writing pad with a pen, in C # can actually be achieved, the general idea is to deal with the mouse coordinates and graphics,
The code is as follows:
Declare two global variables first
BOOL Ismousedown = false; Point point = new Point ();
Re-overriding the MouseDown event:
protected override void OnMouseDown (MouseEventArgs e) {point = e.location;//Current coordinates Ismousedown = true;// Indicates that the mouse has been pressed }
Because when you write, you need to move around, you also rewrite the move event:
protected override void OnMouseMove (MouseEventArgs e) { if (Ismousedown) { using (Graphics G = this. CreateGraphics ()) { g.smoothingmode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using (Pen pen=new pen (color.black,3f))//Brush { g.drawline (pen, point, e.location);//start drawing line point = e. location;//Update Coordinates}}}}
As a final step, rewrite the MouseUp event to:
protected override void OnMouseUp (MouseEventArgs e) { Ismousedown = false; }
As follows: initial interface
Interface for writing
C # simulates mouse writing