Private Sub picPaint_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picPaint.MouseDown
mousePos = New Point(((picPaint.AutoScrollOffset.X + e.X) - (picPaint.AutoScrollOffset.X + e.X) Mod zoomFactor), ((picPaint.AutoScrollOffset.Y + e.Y) - (picPaint.AutoScrollOffset.Y + e.Y) Mod zoomFactor))
'Stop
lorButton = e.Button
Select Case selectedTool
Case 7 'rectangle
startPos = New Point(mousePos.X, mousePos.Y)
undoStack.Push(DirectCast(pic.Clone, Bitmap))
RibbonButton32.Enabled = CBool(undoStack.Count)
End Select
Application.DoEvents()
End Sub
Private Sub picPaint_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picPaint.MouseMove
mousePos = New Point(((picPaint.AutoScrollOffset.X + e.X) - (picPaint.AutoScrollOffset.X + e.X) Mod zoomFactor), ((picPaint.AutoScrollOffset.Y + e.Y) - (picPaint.AutoScrollOffset.Y + e.Y) Mod zoomFactor))
lblCoordinates.Text = mousePos.X & "," & mousePos.Y
objectSize = Nothing
Select Case selectedTool
Case 7 'rectangle
If startPos <> Nothing Then
tempPic = DirectCast(pic.Clone, Bitmap)
Dim gr As Graphics = Graphics.FromImage(tempPic)
Dim r As Rectangle
If fillStyle = 1 Then
Dim color1 As Color
If lorButton = Windows.Forms.MouseButtons.Left Then
color1 = leftColor
ElseIf lorButton = Windows.Forms.MouseButtons.Right Then
color1 = rightColor
End If
If mousePos.X > startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(startPos.X, startPos.Y, mousePos.X - startPos.X, mousePos.Y - startPos.Y)
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X < startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(mousePos.X, startPos.Y, startPos.X - mousePos.X, mousePos.Y - startPos.Y)
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X > startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(startPos.X, mousePos.Y, mousePos.X - startPos.X, startPos.Y - mousePos.Y)
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X < startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(mousePos.X, mousePos.Y, startPos.X - mousePos.X, startPos.Y - mousePos.Y)
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
End If
ElseIf fillStyle = 2 Then
Dim color1 As Color
Dim color2 As Color
If lorButton = Windows.Forms.MouseButtons.Left Then
color1 = leftColor
color2 = rightColor
ElseIf lorButton = Windows.Forms.MouseButtons.Right Then
color1 = rightColor
color2 = leftColor
End If
If mousePos.X > startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(startPos.X, startPos.Y, mousePos.X - startPos.X, mousePos.Y - startPos.Y)
gr.FillRectangle(New SolidBrush(color2), New Rectangle(startPos.X, startPos.Y, mousePos.X - startPos.X, mousePos.Y - startPos.Y))
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X < startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(mousePos.X, startPos.Y, startPos.X - mousePos.X, mousePos.Y - startPos.Y)
gr.FillRectangle(New SolidBrush(color2), New Rectangle(mousePos.X, startPos.Y, startPos.X - mousePos.X, mousePos.Y - startPos.Y))
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X > startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(startPos.X, mousePos.Y, mousePos.X - startPos.X, startPos.Y - mousePos.Y)
gr.FillRectangle(New SolidBrush(color2), New Rectangle(startPos.X, mousePos.Y, mousePos.X - startPos.X, startPos.Y - mousePos.Y))
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
ElseIf mousePos.X < startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(mousePos.X, mousePos.Y, startPos.X - mousePos.X, startPos.Y - mousePos.Y)
gr.FillRectangle(New SolidBrush(color2), New Rectangle(mousePos.X, mousePos.Y, startPos.X - mousePos.X, startPos.Y - mousePos.Y))
gr.DrawRectangle(New Pen(color1, lineWidth * zoomFactor), r)
End If
ElseIf fillStyle = 3 Then
Dim color1 As Color
If lorButton = Windows.Forms.MouseButtons.Left Then
color1 = leftColor
ElseIf lorButton = Windows.Forms.MouseButtons.Right Then
color1 = rightColor
End If
If mousePos.X > startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(startPos.X, startPos.Y, mousePos.X - startPos.X, mousePos.Y - startPos.Y)
gr.FillRectangle(New SolidBrush(color1), r)
ElseIf mousePos.X < startPos.X And mousePos.Y > startPos.Y Then
r = New Rectangle(mousePos.X, startPos.Y, startPos.X - mousePos.X, mousePos.Y - startPos.Y)
gr.FillRectangle(New SolidBrush(color1), r)
ElseIf mousePos.X > startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(startPos.X, mousePos.Y, mousePos.X - startPos.X, startPos.Y - mousePos.Y)
gr.FillRectangle(New SolidBrush(color1), r)
ElseIf mousePos.X < startPos.X And mousePos.Y < startPos.Y Then
r = New Rectangle(mousePos.X, mousePos.Y, startPos.X - mousePos.X, startPos.Y - mousePos.Y)
gr.FillRectangle(New SolidBrush(color1), r)
End If
End If
objectSize = New Size(r.Width, r.Height)
lblSize.Text = objectSize.Width & "," & objectSize.Height
picPaint.Image = tempPic
End If
End Select
Application.DoEvents()
End Sub