Double buffering technology in C # GDI drawing

Source: Internet
Author: User

The most common image window flicker problem is encountered in recent WinForm projects involving the use of GDI to draw waveform graphs. Before going to the interview process was also asked how to solve the problem of image flicker during the drawing process.

Today on the actual project and the reading of some of the double-buffering technology of the article about their understanding of double buffering technology. The main reference article is from 7849880.

First, the cause of flicker

The form needs to be redrawn when the WM_PAINT message is started during the drawing process, the process first erases the background color of the form, and then draws the image to the form. Once the two actions do not occur at the same time, the first erase background color, the phenomenon of drawing images, it looks like the image has been flashing.

Second, the solution:

Use double buffering techniques to draw.

Three, the principle of double buffering technology:

The image is drawn in a buffer before the result of the buffer is output to the form. That is, when a window is refreshed, all elements are displayed to the window at the same time.

Four, the method of operating double buffering in C #.

1, using the default double buffering

(1) The easiest way to do this is through the default double buffering of forms and controls provided by the. Net Framework: Set form and control properties doublebuffered = true;

          

(2) Use the SetStyle method does not enable default double buffering for forms and controls. Add the settings related code to the constructor.

This method is also applied in the project.

2. Manually manage double buffering

Manually managing double buffering is a separate memory for double buffering, in which the drawing is completed and then displayed to the form.

 

Double buffering technology in C # GDI drawing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.