Advertisement
Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace l8_2015
  12. {
  13. public partial class Form1 : Form
  14.  
  15. {
  16. Color CurrentColor = Color.Black; //Default color
  17. Point CurrentPoint; //Current Position
  18. Point PrevPoint; //Previous Position
  19. bool isPressed;
  20. Graphics g;
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. g = panel1.CreateGraphics();
  26. }
  27.  
  28. private void button2_Click(object sender, EventArgs e)
  29. {
  30. panel1.Refresh();
  31. }
  32.  
  33. private void button1_Click(object sender, EventArgs e)
  34. {
  35. DialogResult D = colorDialog1.ShowDialog();
  36. if (D == System.Windows.Forms.DialogResult.OK)
  37. CurrentColor = colorDialog1.Color;
  38.  
  39. }
  40.  
  41. private void panel1_MouseUp(object sender, MouseEventArgs e)
  42. {
  43. isPressed = false;
  44. }
  45.  
  46. private void panel1_MouseMove(object sender, MouseEventArgs e)
  47. {
  48. if (isPressed)
  49. {
  50. PrevPoint = CurrentPoint;
  51. CurrentPoint = e.Location;
  52. paint_simple();
  53. }
  54. }
  55.  
  56. private void panel1_MouseDown(object sender, MouseEventArgs e)
  57. {
  58. isPressed = true;
  59. CurrentPoint = e.Location;
  60. }
  61. private void paint_simple()
  62. {
  63. Pen p = new Pen(CurrentColor);
  64. g.DrawLine(p, PrevPoint, CurrentPoint);
  65. }
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement