C # Double Buffer plotting

Source: Internet
Author: User
Analysis of the key causes of flickering images:

1. During the repainting operation due to the size and position status changes in the drawing window
Each time the content or size of the drawing window changes, you must call the paint event to repaint the screen. This operation will refresh the screen once again to maintain normal display of the window. During the refresh process, all elements will be re-drawn, and the re-painting operation of each element will not cause the painting event. Therefore, each refresh of the window will only call the painting event once. During a Window refresh, the re-painting of each element is immediately displayed in the window. Therefore, as long as the position of the element in the window is refreshed, however, the refresh time is different, and flickering occurs naturally.
Therefore, the key factor that causes the window to flash at this time is not the number of paint event calls, but the re-painting of each element.
According to the above analysis, when the number of images is small, there are not many windows to refresh, and the window flash effect is not serious. When the number of elements is large, the number of elements for repainting in the drawing window increases, every refresh in the drawing window will lead to a large number of elements to be re-drawn. The window is refreshed in many locations, and flickering will naturally become more and more serious. In particular, if the element is relatively large and the painting time is relatively long, the flash problem will be more serious, because the time delay will be longer.
The key to solving the preceding problem is that all elements are displayed in the window at the same time when the window is refreshed.

II,When you move the mouse to draw or perform deformation operations on the Elements
When you use the mouse to track and draw objects or perform deformation on elements, the paint event occurs frequently, which greatly increases the number of refresh windows. Although all elements are displayed in the window at the same time during a Window refresh, there is also a time delay, because the interval between window refreshes is much less than the time each time the elements are displayed in the window. Therefore, flashes cannot be completely eliminated!
Therefore, the key factor that causes the window to flash at this time is the number of times the paint event occurs.
The key to solving this problem is to set several key attributes of a form or control.

Key Technologies of dual buffering:
1. Set the attributes of the display element control to make the effect more obvious.
This . Setstyle (controlstyles. optimizeddoublebuffer | controlstyles. resizeredraw | controlstyles. allpaintinginwmpaint, True );
2. When the window is refreshed, all elements are displayed in the window at the same time.
Bitmap BMP = Null ;
Graphics g_bmp = Null ;
BMP = New Bitmap ( This . Width, This . Height );
G_bmp = graphics. fromimage (BMP );
G_bmp .clear ( This . Backcolor );
G_bmp .drawstring ( " Redraw " , This . Font,New Solidbrush ( This . Forecolor ), This . Location. x + 1 , This . Location. Y + 1 );
This . Refresh ();
// Implement the following in the onpaint method: Code
Private Void This_paint ( Object Sender, painteventargs E)
{
Graphics G = E. graphics;
If (G = Null ) Return ;
If (G_bmp! = Null )
{
G. drawimage (image) BMP, 0 , 0 );
}
}

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.