This is the C# equivalent to the thread here

The following is just the code, to receive detailed explanations please view the VB thread at the link above. All credits go to jmcilhinney, the code is his.

csharp Code:
  1. public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();
  6.  
  7.             //Add EventHandlers
  8.             this.pictureBox1.MouseDown += new MouseEventHandler(this.PictureBox1_MouseDown);
  9.             this.pictureBox1.MouseUp += new MouseEventHandler(this.PictureBox1_MouseUp);
  10.             this.pictureBox1.Paint += new PaintEventHandler(this.PictureBox1_Paint);
  11.         }
  12.  
  13.         //The lines that have been drawn but not saved.
  14.         private List<Line> lines = new List<Line>();
  15.  
  16.         //The start point of the line currently being drawn.
  17.         private Point start;
  18.  
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             //Place a blank image in the PictureBox control.
  22.             this.pictureBox1.Image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
  23.         }
  24.         private void PictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  25.         {
  26.             //Remember the point at which the line started.
  27.             this.start = e.Location;
  28.         }
  29.         private void PictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  30.         {
  31.             //Remember the point at which the line ended.
  32.             Point end = e.Location;
  33.  
  34.             //Add the new line to the list.
  35.             this.lines.Add(new Line(this.start, end));
  36.  
  37.             Rectangle area = new Rectangle(Math.Min(this.start.X, end.X),
  38.                                            Math.Min(this.start.Y, end.Y),
  39.                                            Math.Abs(this.start.X - end.X),
  40.                                            Math.Abs(this.start.Y - end.Y));
  41.  
  42.             //Inflate the rectangle by 1 pixel in each direction to ensure every changed pixel will be redrawn.
  43.             area.Inflate(1, 1);
  44.  
  45.             //Force the control to repaint so the new line is drawn.
  46.             this.pictureBox1.Invalidate(area);
  47.             this.pictureBox1.Update();
  48.         }
  49.         private void PictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  50.         {
  51.             //Draw each line on the control.
  52.             this.DrawLines(e.Graphics);
  53.         }
  54.         private void Save()
  55.         {
  56.             //Create a Graphics object from the Image in the PictureBox.
  57.             using (Graphics g = Graphics.FromImage(this.pictureBox1.Image))
  58.             {
  59.                 //Draw each line on the image to make them permanent.
  60.                 this.DrawLines(g);
  61.             }
  62.  
  63.             //Clear the temporary lines that were just saved.
  64.             this.Clear();
  65.         }
  66.         private void Clear()
  67.         {
  68.             //Clear all unsaved lines.
  69.             this.lines.Clear();
  70.  
  71.             //Force the control to repaint so the lines are removed.
  72.             this.pictureBox1.Refresh();
  73.         }
  74.         private void DrawLines(Graphics g)
  75.         {
  76.             foreach (Line line in this.lines)
  77.             {
  78.                 g.DrawLine(Pens.Black, line.start, line.end);
  79.             }
  80.         }
  81.  
  82.     }
  83.  
  84.     public class Line
  85.     {
  86.         //The line's start point.
  87.         public Point start
  88.         {
  89.             get { return _start; }
  90.             set { _start = value; }
  91.         }
  92.         //The line's end point.
  93.         public Point end
  94.         {
  95.             get { return _end; }
  96.             set { _end = value; }
  97.         }
  98.  
  99.         public Line() : this(Point.Empty, Point.Empty)
  100.         {
  101.         }
  102.  
  103.         public Line(Point start, Point end)
  104.         {
  105.             this._end = end;
  106.             this._start = start;
  107.         }
  108.  
  109.         private Point _start;
  110.         private Point _end;
  111.     }