This article is very good. We recommend you read it all.

Source: Internet
Author: User

Tips and Tricks
Contents
Flicker free drawing in controls
Embedding bitmaps in your manifest
Creating type safe collections the quick way
Flicker free drawing in controls
You have just spent several days writing a beautiful looking custom control but are faced with one last problem that is spoiling the whole effect. whenever the control is redrawn it flickers. this is most obvious when the control is being resized and so redrawn when times in succession.
Solving this problem is very easy with. NET Framework. if you come from a C ++ and GDI background then the solution was to create a memory based bitmap, draw the control onto the bitmap and then bits this to the screen (otherwise known as double buffering ). this is such a common requirement that the UserControl class actually implements this functionality for you. all you need to do is include the following two lines of code into your class constructor.
SetStyle (ControlStyles. DoubleBuffer, true );
SetStyle (ControlStyles. AllPaintingInWmPaint, true );
The first line will request that double buffering be used whenever the OnBackground or OnPaint methods are called. this will reduce then amount of flicker but may not remove it completely as painting the whole control still results in two separate blitting operations.
The second line of code above is used to ensure that only a single blitting operation occurs when drawing. this occurs when the underlying windows WM_PAINT message is processed. when this happens it will create the memory bitmap, call the OnBackground method, call the OnPaint method and then finally blit then result to the screen.

Related Article

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.