Advertisement
goshbigboss

Untitled

Jan 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 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 _2056
  12. {
  13. public partial class myPaint : Form
  14. {
  15. /*Variables*/
  16. /*Start position of mouse on the canvas*/
  17. private int mouseStartX = 0;
  18. private int mouseStartY = 0;
  19. /*Current position of the mouse on the canvas*/
  20. private int mouseCurrentX = 0;
  21. private int mouseCurrentY = 0;
  22. /*Start position for rectangle on the canvas*/
  23. private int recStartPositionX = 0;
  24. private int recStartPositionY = 0;
  25. /*Size of the rectangle on the canvas*/
  26. private int recSizeY = 0;
  27. private int recSizeX = 0;
  28. /*Chek if mouse is down*/
  29. private bool mouseDown = false;
  30. /*Bitmap objects*/
  31. private Bitmap bm;
  32. /*Determine what shape is selected*/
  33. private int shapeSelected = 0;
  34. /*Color of the line of the shapes*/
  35. private Color linePaintColor;
  36. /*Color of the fill line of the shapes*/
  37. private Color lineFillPaintColor;
  38.  
  39.  
  40. public myPaint()
  41. {
  42. InitializeComponent();
  43. bm = new Bitmap(paint_Canvas.Width, paint_Canvas.Height);
  44. linePaintColor = Color.Black;
  45. lineFillPaintColor = Color.Black;
  46. }
  47.  
  48. private void paint_Canvas_Paint(object sender, PaintEventArgs e)
  49. {
  50. Graphics gPaint = e.Graphics;
  51. if (mouseDown == true)
  52. {
  53. Pen size = new Pen(linePaintColor);
  54. if (shapeSelected == 1)
  55. {
  56. gPaint.DrawLine(size, new Point(mouseStartX, mouseStartY),
  57. new Point(mouseCurrentX + mouseStartX, mouseCurrentY + mouseStartY));
  58. }
  59. else if (shapeSelected == 2)
  60. {
  61. gPaint.DrawEllipse(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
  62. }
  63. else if (shapeSelected == 3)
  64. {
  65. gPaint.DrawRectangle(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
  66.  
  67. }
  68.  
  69. }
  70. gPaint.DrawImage(bm, new Point(0, 0));
  71.  
  72. }
  73.  
  74. private void ToolBar_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  75. {
  76.  
  77. }
  78.  
  79. private void paint_Canvas_MouseUp(object sender, MouseEventArgs e)
  80. {
  81. mouseDown = false;
  82.  
  83.  
  84.  
  85. }
  86.  
  87. private void paint_Canvas_MouseDown(object sender, MouseEventArgs e)
  88. {
  89. Pen size1 = new Pen(linePaintColor);
  90. Graphics gPaint = Graphics.FromImage(bm);
  91. if (mouseDown = true)
  92. {
  93.  
  94. mouseStartX = e.X;
  95. mouseStartY = e.Y;
  96. mouseCurrentX = e.X - mouseStartX;
  97. mouseCurrentY = e.Y - mouseStartY;
  98.  
  99. }
  100.  
  101. if(e.Button == MouseButtons.Left)
  102. {
  103. Pen size = new Pen(linePaintColor);
  104.  
  105. mouseDown = true;
  106. Graphics gPaint1 = Graphics.FromImage(bm);
  107.  
  108. if(shapeSelected == 1)
  109. {
  110. gPaint.DrawLine(size, new Point(mouseStartX, mouseStartY),
  111. new Point(mouseCurrentX + mouseStartX, mouseCurrentY + mouseStartY));
  112.  
  113. }
  114. else if (shapeSelected == 2)
  115. {
  116. gPaint.DrawEllipse(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
  117.  
  118. }
  119. else if (shapeSelected == 3)
  120. {
  121. gPaint.DrawRectangle(size, mouseStartX, mouseStartY, mouseCurrentX, mouseCurrentY);
  122.  
  123.  
  124. }
  125.  
  126. }
  127. }
  128. private void paint_Canvas_MouseMove(object sender, MouseEventArgs e)
  129. {
  130.  
  131.  
  132.  
  133.  
  134.  
  135. if (mouseDown == true)
  136. {
  137. mouseCurrentX = e.X - mouseStartX;
  138. mouseCurrentY = e.Y - mouseStartY;
  139.  
  140. paint_Canvas.Invalidate();
  141. }
  142. else
  143. {
  144. paint_Canvas.Invalidate();
  145. }
  146. recStartPositionX = Math.Min(mouseStartX, e.X);
  147. recStartPositionY = Math.Min(mouseStartY, e.Y);
  148. recSizeX = Math.Max(mouseStartX, e.X);
  149. recSizeY = Math.Max(mouseStartY, e.Y);
  150. }
  151.  
  152. private void lineBtn_Click(object sender, EventArgs e)
  153. {
  154. shapeSelected = 1;
  155. }
  156.  
  157. private void circleBtn_Click(object sender, EventArgs e)
  158. {
  159. shapeSelected = 2;
  160. }
  161.  
  162. private void square_Btn_Click(object sender, EventArgs e)
  163. {
  164. shapeSelected = 3;
  165. }
  166.  
  167. private void black_Btn_Click(object sender, EventArgs e)
  168. {
  169. linePaintColor = Color.Black;
  170. }
  171.  
  172. private void red_Btn_Click(object sender, EventArgs e)
  173. {
  174. linePaintColor = Color.Red;
  175. }
  176.  
  177. private void blue_Btn_Click(object sender, EventArgs e)
  178. {
  179. linePaintColor = Color.Blue;
  180. }
  181.  
  182. private void green_Btn_Click(object sender, EventArgs e)
  183. {
  184. linePaintColor = Color.Green;
  185. }
  186.  
  187. private void yellow_Btn_Click(object sender, EventArgs e)
  188. {
  189. linePaintColor = Color.Yellow;
  190. }
  191.  
  192. private void purple_Btn_Click(object sender, EventArgs e)
  193. {
  194. linePaintColor = Color.Purple;
  195. }
  196.  
  197. private void otherColors_Btn_Click(object sender, EventArgs e)
  198. {
  199. ColorDialog colorWheel = new ColorDialog();
  200. if (colorWheel.ShowDialog() == DialogResult.OK)
  201. {
  202. linePaintColor = colorWheel.Color;
  203. }
  204. }
  205.  
  206. private void toolStripButton15_Click(object sender, EventArgs e)
  207. {
  208. lineFillPaintColor = Color.Black;
  209. }
  210.  
  211. private void toolStripButton16_Click(object sender, EventArgs e)
  212. {
  213. lineFillPaintColor = Color.Red;
  214. }
  215.  
  216. private void toolStripButton17_Click(object sender, EventArgs e)
  217. {
  218. lineFillPaintColor = Color.Blue;
  219. }
  220.  
  221. private void toolStripButton18_Click(object sender, EventArgs e)
  222. {
  223. lineFillPaintColor = Color.Green;
  224. }
  225.  
  226. private void toolStripButton19_Click(object sender, EventArgs e)
  227. {
  228. lineFillPaintColor = Color.Yellow;
  229. }
  230.  
  231. private void toolStripButton20_Click(object sender, EventArgs e)
  232. {
  233. lineFillPaintColor = Color.Purple;
  234. }
  235.  
  236. private void toolStripButton21_Click(object sender, EventArgs e)
  237. {
  238. ColorDialog colorWheel1 = new ColorDialog();
  239. if (colorWheel1.ShowDialog() == DialogResult.OK)
  240. {
  241. lineFillPaintColor = colorWheel1.Color;
  242. }
  243. }
  244.  
  245. private void clrBtn_Click(object sender, EventArgs e)
  246. {
  247. Graphics gPaint = CreateGraphics();
  248. gPaint.Clear(SystemColors.Control);
  249. }
  250. }
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement