Mike Moyle
Mike Moyle

Reputation:

Picture box goes blank

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.

Upvotes: 3

Views: 1569

Answers (6)

Rafa
Rafa

Reputation: 2368

Usually, if you're drawing something on a picture box or on another control, you have to take over the OnPaint event, and you're responsible of persisting what you draw on this event.

Upvotes: 1

Patrick Desjardins
Patrick Desjardins

Reputation: 140923

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.

Upvotes: 0

Mike Moyle
Mike Moyle

Reputation:

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.

Upvotes: 0

liggett78
liggett78

Reputation: 11358

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.).

Upvotes: 0

Mike Moyle
Mike Moyle

Reputation:

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.

Upvotes: 0

Andrew Rollings
Andrew Rollings

Reputation: 14571

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.

Upvotes: 1

Related Questions