1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
Private Sub DmdPictureBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DmdPictureBox.MouseDown
down = True ' checks if the mouse button is pressed
canvas.Parent = Me ' Set the form as the parent of the ShapeContainer
If LineChoice = True Then 'Entered if you clicked Draw Line
TempLine = New LineShape ' Set the shape of the form as a line
TempLine.Parent = canvas ' Set the ShapeContainer as the parent of the LineShape
TempLine.Parent.Parent = DmdPictureBox
TempLine.BorderColor = Color.Black 'indicates the border color to use
TempLine.BorderStyle = Drawing2D.DashStyle.Solid 'indicates the way to use the border color (solid)
ptA = New Point(e.X, e.Y) 'Gets the cursor's x and y position and register it as a starting point
TempLine.StartPoint = ptA 'sets the starting point
TempLine.EndPoint = ptA 'set the ending point which doesn't exit yet because we still haven't moved or released the mouse button -->Next sub
TempLine.BorderWidth = linesize
ElseIf RectangleChoice = True Then 'Entered if you chose Draw Rectangle, only the different lines will be explaine
ptA = New Point(e.X, e.Y)
TempRectangle = New RectangleShape
TempRectangle.Parent = canvas
TempRectangle.Parent.Parent = DmdPictureBox
TempRectangle.BorderColor = Color.Black
TempRectangle.BackColor = Color.Black 'indicates the backcolor to use
TempRectangle.BackStyle = PowerPacks.BackStyle.Opaque 'indicates the way to use the backcolor (opaque so that it's not transparent)
TempRectangle.BorderStyle = Drawing2D.DashStyle.Solid
TempRectangleX1 = e.X 'sets the x coordinate or the cursor as the top left x coordinate of the rectangle
TempRectangleY1 = e.Y 'set the y coordinate of the cursor as the top left y coordinate of the rectangle
ElseIf OvalChoice = True Then 'Entered if you chose Draw Oval, , only the different lines will be explained
TempOval = New OvalShape
TempOval.Parent = canvas
TempOval.Parent.Parent = DmdPictureBox
TempOval.BorderColor = Color.Black
TempOval.BackColor = Color.Black
TempOval.BackStyle = PowerPacks.BackStyle.Opaque
TempOval.BorderStyle = Drawing2D.DashStyle.Solid
ptA = New Point(e.X, e.Y) 'set the location where the clicked was made as the top left point of the oval (basically his position)
TempOvalX1 = e.X 'will be used in a calculation later
TempOvalY1 = e.Y 'will be used in a calculation later
End If
End Sub
Private Sub DmdPictureBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DmdPictureBox.MouseMove
If down = True Then 'Needs the mouse button to be pressed
If LineChoice = True Then
TempLine.X2 = e.X 'this line and the following one make the coordinates of the ending point follow the coordinates of the cursor while it's moving
TempLine.Y2 = e.Y 'see line above
ElseIf RectangleChoice = True Then
TempRectangleX2 = e.X 'this line and the following one make the coordinates of the bottom right of the rectangle follow the coordinates of the cursor while it's moving
TempRectangleY2 = e.Y 'see line above
TempRectangle.Location = ptA 'needed so that the program remembers the starting point (location of the rectangle) while moving the ending point (bottom right point)
TempRectangle.Width = TempRectangleX2 - TempRectangleX1 'calculates the width of the rectangle by substracting the ending point x coordinates to the starting point x coordinate
TempRectangle.Height = TempRectangleY2 - TempRectangleY1 'calculates the height of the rectangle by substracting the ending point y coordinates to the starting point y coordinate
ElseIf OvalChoice = True Then
TempOvalX2 = e.X 'this line and the following one make the coordinates of the bottom right of the oval follow the coordinates of the cursor while it's moving
TempOvalY2 = e.Y 'see line above
TempOval.Width = TempOvalX2 - TempOvalX1 'calculates the width of the oval by substracting the ending point x coordinates to the starting point x coordinate
TempOval.Height = TempOvalY2 - TempOvalY1 'calculates the width of the oval by substracting the ending point x coordinates to the starting point x coordinate
TempOval.Location = New Point(ptA) 'needed so that the program remembers the starting point (location of the oval) while moving the ending point (bottom right point)
TempOval.Size = New System.Drawing.Size(TempOval.Width, TempOval.Height) 'receives the result of the calcultions above (width and height) and shows the resulting oval
End If
End If
End Sub
Private Sub DmdPictureBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DmdPictureBox.MouseUp
down = False 'checks if the mouse button isn't pressed
If LineChoice = True Then
ptB = New Point(e.X, e.Y) 'set the x and y coordinates of the cursor as the x and y coordinates of the line ending point
lines.Add(TempLine)
LineCounter = LineCounter + 1
ElseIf RectangleChoice = True Then
TempRectangleX2 = e.X 'sets the x coordinate of the cursor as the bottom right x coordinate of the rectangle
TempRectangleY2 = e.Y 'sets the y coordinate of the cursor as the bottom right y coordinate of the rectangle
rectangles.Add(TempRectangle)
RectangleCounter = RectangleCounter + 1
ElseIf OvalChoice = True Then
TempOvalX2 = e.X 'sets the x coordinate of the cursor as the bottom right x coordinate of the oval
TempOvalY2 = e.Y 'sets the x coordinate of the cursor as the bottom right y coordinate of the oval
ovals.Add(TempOval)
OvalCounter = OvalCounter + 1
End If
End Sub |
Partager