If you are using vb.net and you want to draw line in picturebox control using mouse then
Dim startpoint As Point
Dim endpoint As Point
Dim flag As Boolean = False
Private Sub PictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
startpoint = New Point(e.X, e.Y)
flag = True
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If flag Then
Dim g As Graphics = PictureBox1.CreateGraphics()
endpoint = New Point(e.X, e.Y)
g.Clear(Color.White)
g.DrawLine(Pens.Black, startpoint, endpoint)
End If
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
flag = False
End Sub
If you want to draw line on form window then use
me
instead of
picturebox1
and use form events instead of picturebox mouse events.