views:

651

answers:

6

In VisualBasic.Net When I activate a picture box and then draw something on it, it draws and then immediately goes blank. Works fine when I re-draw it, but almost always messes up the first time I draw on it. This has happenned with several different programs, and the help file is no help.

+1  A: 

Try setting the DoubleBuffered property

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx

If that's not it, please provide more info.

Andrew Rollings
A: 

Thank you Andrew, but no help. I'm using .Net Framework 1.1, which does not offer the DoubleBuffered property... it was new in 2.0.

Not sure what additional info to provide.. the code is 300 lines long. When a button is clicked, the code expands my form, makes two picture boxes visible (one on top of the other (the back one is for some graph labels), and then uses some graphic brushes and pens to draw a graph on the front box. There's some database activity and calculations going on in the background at the same time.

A: 

I assume you're using the standard PictureBox component. Do you draw in the Paint-Handler? If not then the PictureBox will just erase your painted stuff next time it's asked to redraw itself (erase background etc.).

liggett78
A: 

Yes, I believe I am using the standard picture box.

By Paint-Handler, I assume you mean a [Control].PaintEvent Handler. No I'm not using an event handler to do the drawing... drawing my chart is not an event in itself, but part of a much larger response to a button click event.

If you are saying that having the drawing code be part of a separate and specific handler can solve my problem, than I guess I could raise an internal event every time I want to redraw the chart. But I Would rather just figure out what is causing the PB to redraw itself without being told to.

A: 

If you cannot use the DoubleBuffered than you can HIDE a second picture box. You do the drawing in it and once it's completed you draw back to the VISIBLE one. This way the process of drawing is done on the hidden one and the white/flickering will not be shown.

Daok
A: 

Talk about some hacks! ;) ... why don't you just upgrade? 1.1 is pretty old I think?

hmcclungiii