Painting on PictureBox

  • Thread starter Thread starter Tim Bücker
  • Start date Start date
T

Tim Bücker

Hello.

I want to paint some geometric shapes on the graphic context from a picture
box. This picture box has dock style set to fill and is filling out the
whole form. The form is maximized. This is working very good and fast but
the problem is, that I want to have some kind of background image.

Doing so the performance is going down extremly. Even though I am using
double buffering, invalidating only the regions nessecary and using all the
other performance tricks I know...

So can someone tell me how it is possible in .NET to paint on a picture
(fullscreen) with GDI(+) and be fast enough that shapes being dragged around
are not running behind the mouse.

Thanks really a lot for any tips and tricks!
Greetings,
Tim.
 
Shapes being dragged. I would recommend rendering a *drag box* or reversible
box using ControlPaint, and then only moving the graphic element when the user
is done. This eliminates your redraw while your control is *in motion*.
 
Justin Rogers said:
Shapes being dragged. I would recommend rendering a *drag box* or reversible
box using ControlPaint, and then only moving the graphic element when the user
is done. This eliminates your redraw while your control is *in motion*.

First, thanks for answering!
But unfortunately I am already moving just rectangles and no complex shapes.

It seems (due to the lack of performance) as although I give invalidate a
rectangle, the whole background picture is redrawn...
That seems to be the problem somehow... But to be frank I have no idea.

Greetings and thanks again,
Tim.
 
DrawReversible* doesn't require that you invalidate and repaint the background,
instead
you delay the invalidate until the user has selected a location where they want
to move the
object. Only then do you invalidate the source location *repaint the
background* and
the target location *repaint the object in question.

What you have to realize is that you can repaint controls only a few times a
second, not
the hundreds of times that can be introduced by using real-time mouse-movements.
You
have to throttle the process of updating the screen to prevent poor performance.
Since
reversible lines don't require that you fill or repaint, you can draw a
reversible rectangle in
one spot, then simply redraw it again in the same spot and it disappears. You
can do this
thousands of times per second until the user has completed their drag operation.
 
Justin Rogers said:
DrawReversible* doesn't require that you invalidate and repaint the background,
instead
you delay the invalidate until the user has selected a location where they want
to move the
object. Only then do you invalidate the source location *repaint the
background* and
the target location *repaint the object in question.

@Justin Rogers:

Thanks - Thanks - Thanks.
You´ve saved my day!

Just wrote a little test program - it is working greatly and with enormous
performance!!!
Greetings,
Tim.
 
Back
Top