Browse Source

added draw function

TiReischl 5 years ago
parent
commit
04ccbc51b0

+ 30 - 1
SketchAssistant/SketchAssistant/Form1.Designer.cs

@@ -42,6 +42,9 @@ namespace SketchAssistant
             this.toolStripLoadStatus = new System.Windows.Forms.ToolStripStatusLabel();
             this.backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
             this.timer1 = new System.Windows.Forms.Timer(this.components);
+            this.edittoolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.painttoolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.timer2 = new System.Windows.Forms.Timer(this.components);
             this.tableLayoutPanel1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBoxRight)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLeft)).BeginInit();
@@ -79,6 +82,9 @@ namespace SketchAssistant
             this.pictureBoxRight.Size = new System.Drawing.Size(344, 434);
             this.pictureBoxRight.TabIndex = 6;
             this.pictureBoxRight.TabStop = false;
+            this.pictureBoxRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBoxRight_MouseDown);
+            this.pictureBoxRight.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBoxRight_MouseMove);
+            this.pictureBoxRight.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBoxRight_MouseUp);
             // 
             // pictureBoxLeft
             // 
@@ -96,7 +102,8 @@ namespace SketchAssistant
             // menuStrip1
             // 
             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.fileToolStripMenuItem});
+            this.fileToolStripMenuItem,
+            this.edittoolStripMenuItem});
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
             this.menuStrip1.MaximumSize = new System.Drawing.Size(1000, 0);
             this.menuStrip1.Name = "menuStrip1";
@@ -159,6 +166,25 @@ namespace SketchAssistant
             this.timer1.Interval = 10;
             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
             // 
+            // edittoolStripMenuItem
+            // 
+            this.edittoolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.painttoolStripMenuItem});
+            this.edittoolStripMenuItem.Name = "edittoolStripMenuItem";
+            this.edittoolStripMenuItem.Size = new System.Drawing.Size(39, 20);
+            this.edittoolStripMenuItem.Text = "Edit";
+            // 
+            // painttoolStripMenuItem
+            // 
+            this.painttoolStripMenuItem.Name = "painttoolStripMenuItem";
+            this.painttoolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+            this.painttoolStripMenuItem.Text = "Paint";
+            this.painttoolStripMenuItem.Click += new System.EventHandler(this.painttoolStripMenuItem_Click);
+            // 
+            // timer2
+            // 
+            this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -203,6 +229,9 @@ namespace SketchAssistant
         private System.Windows.Forms.PictureBox pictureBoxRight;
         private System.Windows.Forms.PictureBox pictureBoxLeft;
         private System.Windows.Forms.Timer timer1;
+        private System.Windows.Forms.ToolStripMenuItem edittoolStripMenuItem;
+        private System.Windows.Forms.ToolStripMenuItem painttoolStripMenuItem;
+        private System.Windows.Forms.Timer timer2;
     }
 }
 

+ 79 - 0
SketchAssistant/SketchAssistant/Form1.cs

@@ -97,5 +97,84 @@ namespace SketchAssistant
         {
 
         }
+
+        //Beginn userstory4
+        Bitmap skizze = null;
+        Graphics graph = null;
+        int x = 0;
+        int y = 0;
+        PointF[] points = new PointF[10]; //array Mousepositons
+        int i = 0;
+        PointF first;
+        PointF second;
+        bool clicked = false; //Button "Paint" is clicked or not
+        PointF p;// = new PointF(x, y);
+        bool mousedown = false;
+        Pen pen = new Pen(Color.Black);
+
+
+        //Create an image relative to the mouse positions, which the method gets from pictureBoxRight_MouseMove
+        public void addPath(PointF p)
+        {
+            points[i] = p;
+            graph = Graphics.FromImage(skizze);
+            first = points[0];
+
+
+            if (i == 1)
+            {
+                second = points[1];
+
+                graph.DrawLine(pen, first, second);
+                points[0] = second;
+                i = 0;
+            }
+
+        }
+
+        // creates an empty image and prepares rightPictureBox for drawing
+        private void painttoolStripMenuItem_Click(object sender, EventArgs e)
+        {
+            skizze = new Bitmap(500, 800);
+            graph = Graphics.FromImage(skizze);
+            graph.FillRectangle(Brushes.White, 0, 0, 500, 800);
+            pictureBoxRight.Image = skizze;
+            timer2.Enabled = !clicked;
+            clicked = !clicked;
+        }
+
+        //add a Point on every tick to the Drawpath
+        private void timer2_Tick(object sender, EventArgs e)
+        {
+            timer2.Interval = 100;
+            if (clicked && mousedown)
+            {
+                addPath(p);
+                pictureBoxRight.Image = skizze;
+                i++;
+            }
+        }
+
+        //get current Mouse positon
+        private void pictureBoxRight_MouseMove(object sender, MouseEventArgs e)
+        {
+            x = e.X;
+            y = e.Y;
+            p = new PointF(x, y);
+        }
+
+        //hold left mouse button to draw.
+        private void pictureBoxRight_MouseDown(object sender, MouseEventArgs e)
+        {
+            mousedown = true;
+        }
+
+        //Lift left mouse button to stop drawing.
+        private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
+        {
+            mousedown = false;
+        }
+
+        //Ende userstory4
     }
 }

+ 3 - 0
SketchAssistant/SketchAssistant/Form1.resx

@@ -135,6 +135,9 @@
   <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>786, 17</value>
   </metadata>
+  <metadata name="timer2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>873, 17</value>
+  </metadata>
   <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>43</value>
   </metadata>