Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make lines in picture box 1

Status
Not open for further replies.
Aug 1, 2003
39
0
0
US
Just an amateur programmer here.
Trying to on mousemove event to draw a picture with the mouse. Nothing fancy. See where the question marks are in the code? That is where I need to draw in the picBox.

[Private Sub picBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBox.MouseDown
paintHere = True
End Sub

Private Sub picBox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBox.MouseMove
If paintHere Then
Dim g As Graphics
g = picBox.CreateGraphics

??????????????????????????????????????
End If
End Sub

Private Sub picBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBox.MouseUp
paintHere = False
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
picBox.Image = Nothing
End Sub]

--------------------------
Thanks
Brian

 
Maybe something like this?

Code:
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		PictureBox1.Image = Nothing

	End Sub

	Private Drawing As Boolean = False
	Private StartPos As PointF = Nothing

	Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

		Drawing = True
		StartPos = e.Location

	End Sub

	Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

		If Drawing Then
			Dim p As Pen = New Pen(Color.Black)
			Dim g As Graphics = PictureBox1.CreateGraphics
			g.DrawLine(p, StartPos, e.Location)
			StartPos = e.Location
		End If

	End Sub

	Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp

		Drawing = False

	End Sub
End Class


[vampire][bat]
 
Code:
        If Drawing Then
            Dim p As Pen = New Pen(Color.Black)
            Dim g As Graphics = PictureBox1.CreateGraphics
            g.DrawLine(p, StartPos, e.Location)
            StartPos = e.Location
        End If

can be simplified slightly to:

Code:
		If Drawing Then
			Dim g As Graphics = PictureBox1.CreateGraphics
			g.DrawLine(New Pen(Color.Black), StartPos, e.Location)
			StartPos = e.Location
		End If

[vampire][bat]
 
Thanks earthandfire for your help, this helped me out immensely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top