Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. private Bitmap bitmap;
  2. private Point oldPosition;
  3.  
  4. private void Form1_Load(object sender, EventArgs e)
  5. {
  6. bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
  7. using (Graphics g = Graphics.FromImage(bitmap))
  8. g.Clear(Color.White);
  9. pictureBox1.Image = bitmap;
  10. }
  11.  
  12. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  13. {
  14. oldPosition = e.Location;
  15. }
  16.  
  17. * Determine whether the user actually wants to draw (is the left mouse button pressed?).
  18. * Draw the line into the bitmap.
  19. * Update the previous cursor position to the new position.
  20. * Display the results.
  21.  
  22. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  23. {
  24. if (e.Button == System.Windows.Forms.MouseButtons.Left)
  25. {
  26. using (Graphics g = Graphics.FromImage(bitmap))
  27. g.DrawLine(Pens.Black, oldPosition, e.Location);
  28. oldPosition = e.Location;
  29. pictureBox1.Image = bitmap;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement