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

VB.NET Problem's

P: 3
I'm having a problem with drawing on picturebox in 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 24 '06 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,916
Generally nothing is permanent in a window, you have to redraw it when required.

You will know when a redraw is require because Windows sends a WM_PAINT message to the window that requires redrawing. This is available in VB as a handler on some sort (but I do not know the name).

You need to store the start and end point of the lines and when required by windows redraw them.
Mar 24 '06 #2

Post your reply

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