Form1.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. // This is the code for your desktop app.
  11. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
  12. namespace SketchAssistant
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. //Dialog to select a file.
  21. OpenFileDialog openFileDialogLeft = new OpenFileDialog();
  22. //Image loaded on the left
  23. Image leftImage = null;
  24. //Image on the right
  25. Image rightImage = null;
  26. private void Form1_Load(object sender, EventArgs e)
  27. {
  28. this.DoubleBuffered = true;
  29. //Connect the Paint event of the left picture box to the event handler method.
  30. pictureBoxLeft.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxLeft_Paint);
  31. pictureBoxRight.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxRight_Paint);
  32. }
  33. //Resize Function connected to the form resize event, will refresh the form when it is resized
  34. private void Form1_Resize(object sender, System.EventArgs e)
  35. {
  36. this.Refresh();
  37. }
  38. private void pictureBoxLeft_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  39. {
  40. //Draw the left image
  41. if(leftImage != null)
  42. {
  43. pictureBoxLeft.Image = leftImage;
  44. }
  45. }
  46. private void pictureBoxRight_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  47. {
  48. //Draw the right image
  49. if (rightImage != null)
  50. {
  51. pictureBoxRight.Image = rightImage;
  52. }
  53. }
  54. // A Table Layout with one row and two columns.
  55. // Columns are 50% so that the window is evenly split.
  56. // The size is manually set relative to the window size.
  57. // TODO: Maybe change this to automatically be the size of a parent container...
  58. private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
  59. {
  60. }
  61. private void fileToolStripMenuItem_Click(object sender, EventArgs e)
  62. {
  63. }
  64. //Load button, will open an OpenFileDialog
  65. private void loadToolStripMenuItem_Click(object sender, EventArgs e)
  66. {
  67. openFileDialogLeft.Filter = "Image|*.jpg;*.png;*.jpeg";
  68. if(openFileDialogLeft.ShowDialog() == DialogResult.OK)
  69. {
  70. toolStripLoadStatus.Text = openFileDialogLeft.SafeFileName;
  71. leftImage = Image.FromFile(openFileDialogLeft.FileName);
  72. //Refresh the left image box when the content is changed
  73. this.Refresh();
  74. pictureBoxLeft.Refresh();
  75. }
  76. }
  77. private void toolStripStatusLabel1_Click(object sender, EventArgs e)
  78. {
  79. }
  80. private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  81. {
  82. }
  83. private void pictureBoxLeft_Click(object sender, EventArgs e)
  84. {
  85. }
  86. <<<<<<< HEAD
  87. //Beginn userstory4
  88. Bitmap skizze = null;
  89. Graphics graph = null;
  90. int x = 0;
  91. int y = 0;
  92. PointF[] points = new PointF[10]; //array Mousepositons
  93. int i = 0;
  94. PointF first;
  95. PointF second;
  96. bool clicked = false; //Button "Paint" is clicked or not
  97. PointF p;// = new PointF(x, y);
  98. bool mousedown = false;
  99. Pen pen = new Pen(Color.Black);
  100. //Create an image relative to the mouse positions, which the method gets from pictureBoxRight_MouseMove
  101. public void addPath(PointF p)
  102. {
  103. points[i] = p;
  104. graph = Graphics.FromImage(skizze);
  105. first = points[0];
  106. if (i == 1)
  107. {
  108. second = points[1];
  109. graph.DrawLine(pen, first, second);
  110. points[0] = second;
  111. i = 0;
  112. }
  113. }
  114. // creates an empty image and prepares rightPictureBox for drawing
  115. private void painttoolStripMenuItem_Click(object sender, EventArgs e)
  116. {
  117. skizze = new Bitmap(500, 800);
  118. graph = Graphics.FromImage(skizze);
  119. graph.FillRectangle(Brushes.White, 0, 0, 500, 800);
  120. pictureBoxRight.Image = skizze;
  121. timer2.Enabled = !clicked;
  122. clicked = !clicked;
  123. }
  124. //add a Point on every tick to the Drawpath
  125. private void timer2_Tick(object sender, EventArgs e)
  126. {
  127. timer2.Interval = 100;
  128. if (clicked && mousedown)
  129. {
  130. addPath(p);
  131. pictureBoxRight.Image = skizze;
  132. i++;
  133. }
  134. }
  135. //get current Mouse positon
  136. private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
  137. {
  138. x = e.X;
  139. y = e.Y;
  140. p = new PointF(x, y);
  141. }
  142. //hold left mouse button to draw.
  143. private void pictureBoxRight_MouseDown(object sender, MouseEventArgs e)
  144. {
  145. mousedown = true;
  146. }
  147. //Lift left mouse button to stop drawing.
  148. private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
  149. {
  150. mousedown = false;
  151. }
  152. //Ende userstory4
  153. =======
  154. //Button to create a new Canvas. Will create an empty image
  155. //which is the size of the left image, if there is one.
  156. //If there is no image loaded the canvas will be the size of the right picture box
  157. private void toolStripButton1_Click(object sender, EventArgs e)
  158. {
  159. if (leftImage == null)
  160. {
  161. rightImage = new Bitmap(pictureBoxRight.Width, pictureBoxRight.Height);
  162. using (Graphics grp = Graphics.FromImage(rightImage))
  163. {
  164. grp.FillRectangle(Brushes.White, 0, 0, pictureBoxRight.Width + 10, pictureBoxRight.Height + 10);
  165. }
  166. }
  167. else
  168. {
  169. rightImage = new Bitmap(leftImage.Width, leftImage.Height);
  170. using (Graphics grp = Graphics.FromImage(rightImage))
  171. {
  172. grp.FillRectangle(Brushes.White, 0, 0, leftImage.Width + 10, leftImage.Height + 10);
  173. }
  174. }
  175. this.Refresh();
  176. pictureBoxRight.Refresh();
  177. }
  178. >>>>>>> develop
  179. }
  180. }