I have a simple program that you can draw on the screen with FillEllipse and FillRectangle. My problem is that when you drag another window over even a small portion of the screen, that part will be erased. This happens when you drag the other window over, let go, and drag it back off. Is there any way to fix this?
Dim MyFormObject As Graphics = Me.CreateGraphics
Select Case shape
Case "Ellipse"
MyFormObject.FillEllipse(brush, e.X - CInt(brushWidth / 2), e.Y - CInt(brushHeight / 2), brushWidth, brushHeight)
Case "Rectangle"
MyFormObject.FillRectangle(brush, e.X - CInt(brushWidth / 2), e.Y - CInt(brushHeight / 2), brushWidth, brushHeight)
End Select
@SLaks already told you to do all painting in the OnPaint method. Here's a little more information. If you're trying to draw on a form, you would override the OnPaint method and do all you painting using the Graphics instance that is passed into the method. Here is more information on the topic:
http://www.bobpowell.net/creategraphics.htm
http://www.bobpowell.net/picturebox.htm
just a insight, what really helped me with draw in vb.net was this example vbnettuthut.blogspot.com it show a complete example to draw smooth and fast, with working example and source cod
The following code allows you to draw a rectangle with the mouse (click and drag). Add a
PictureBox
to a form.You can put a PictureBox control on your form and draw to that instead and it won't be erased when other windows paint over it:
do this once, on form_load or something:
to draw:
You need to do all of your drawing in the
Paint
event, which fires each time your control gets repainted.