Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Bitmap cursor;
  2. Graphics gCursor;
  3.  
  4. Bitmap canvas;
  5. Graphics gPaint;
  6.  
  7. bool isPainting = false;
  8.  
  9. public MainForm()
  10. {
  11. InitializeComponent();
  12.  
  13. this.DoubleBuffered = true;
  14.  
  15. this.MouseMove += new MouseEventHandler(mouseMove);
  16. this.MouseDown += new MouseEventHandler(mouseDown);
  17. this.MouseUp += new MouseEventHandler(mouseUp);
  18.  
  19. canvas = new Bitmap(this.Width, this.Height);
  20. gPaint = Graphics.FromImage(canvas);
  21.  
  22. cursor = new Bitmap(this.Width, this.Height);
  23. gCursor = Graphics.FromImage(cursor);
  24.  
  25. }
  26.  
  27. protected override void OnPaint(PaintEventArgs e)
  28. {
  29.  
  30. gCursor.Clear(Color.Transparent);
  31.  
  32. Point p = PointToClient(Cursor.Position);
  33.  
  34. if (isPainting)
  35. {
  36. gPaint.FillRectangle(Brushes.Black, new Rectangle(p.X - 20, p.Y - 20, 40, 40));
  37. }
  38.  
  39. gCursor.FillRectangle(Brushes.Black, new Rectangle(p.X - 20, p.Y - 20, 40, 40));
  40. gCursor.DrawRectangle(Pens.Red, new Rectangle(p.X - 20, p.Y - 20, 39, 39));
  41.  
  42. e.Graphics.DrawImage(canvas, Point.Empty);
  43. e.Graphics.DrawImage(cursor, Point.Empty);
  44. }
  45.  
  46. private void mouseMove(object sender, MouseEventArgs e)
  47. {
  48. this.Invalidate();
  49. }
  50.  
  51. private void mouseDown(object sender, MouseEventArgs e)
  52. {
  53. isPainting = true;
  54. }
  55.  
  56. private void mouseUp(object sender, MouseEventArgs e)
  57. {
  58. isPainting = false;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement