O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use Double Buffering to Increase Redraw Speed

Problem

You want to optimize drawing for a form that is frequently refreshed and want to reduce flicker.

Solution

Render the graphics to an in-memory bitmap, and then copy the finalized bitmap to the form.

Discussion

In some applications you need to repaint a form or control frequently. This is commonly the case when performing animation. For example, you might use a timer to invalidate your form every second. Your painting code could then redraw an image at a new location, creating the illusion of motion. The problem with this approach is that every time you invalidate the form, Windows repaints the window background (clearing the form), and then runs your painting code, which draws the graphic element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required