By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

I'm having a problem with drawing on picturebox in vb.net programing.

P: 3
I'm having a problem with drawing on picturebox in vb.net programing.
I draw line(or another shape's) on picturebox, anytime screen refreshes(open dialogbox ro menu,...) the drawn line on picturebox disapears.

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
x1 = e.Location.X
y1 = e.Location.Y
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
x2 = e.Location.X
y2 = e.Location.Y
If toolbox = "line" Then drawline()

Sub drawline()
Dim g As Graphics = PictureBox1.CreateGraphics()
g.DrawLine(Pens.Black, x1, y1, x2, y2)
End Sub
Mar 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: 4
The onpaint event fires every time a form or control needs to be redrawn to the screen. When this happens, your drawline() sub would need to be called too for the line to be redrawn. Your start and end point variables would have to persist outside of the sub as well.
Apr 3 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.