i know there are plenty of questions about how to draw on/in/above an ImageBox but i can't find a good solution to my problem. As you can see, i have some lines which basically work. The problem is that the drawed line isn't under my Cursor. For example: I press the MouseButton at the right edge on my picture, but the line is made somewhere in the middle. I tried nearly everything i can imagine but nothing helps. I hope someone can help me!
Just for you to know: It's a little app which makes a Screenshot of the Screen where the Cursor is, this Screenshot is showed in an ImageBox and now i want to draw on it, for example to make clear what is so important on the Screenshot.
Here's the Code:
Dim previous As System.Nullable(Of Point) = Nothing
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
previous = e.Location
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
If previous IsNot Nothing Then
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawLine(Pens.Red, previous.Value, e.Location)
End Using
PictureBox1.Invalidate()
previous = e.Location
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
previous = Nothing
End Sub