Solutions for flashing problems with several C # controls (GO)

Source: Internet
Author: User

Some recent optimizations have been made to the code, but the results are still available, but the discovery interface flashes, specifically, the TreeView control flashes and the language is c#,ide to VS2005. Looking at some of the data, using some basic techniques (such as turning on double buffering), found nothing.

So using the profiler tool, find out the bottleneck is every time the interface to update the endupdate operation (this is to reduce the number of UI updates, but it is not ideal here because of the number of elements in the control), guess about each update. NET bottom will be updated to redraw each entity, so the speed will be slow, causing flicker. But if so, using double buffering should have a good effect. Looking at the code again, it may be that the update action is too frequent, so it slows down and improves, but it still doesn't work.

Continue to look online, and finally find a solution more appropriate. The primary reason for this flicker is that the underlying redraw will clear the canvas every time and then redraw it all again. Then overload the message send function operation, the message is forbidden. The code is as follows:

protected override void WndProc (ref Message m)

{

if (m.msg = = 0x0014)//Disable erase background message

Return

Base. WndProc (ref m);

}

Success!

Note: Double buffering is also useful when updates are not frequent and the controls contain elements that are not particularly numerous. Once the element is too large, each update time is longer, even if the use of double buffering, still can not solve the flicker problem. Personally think that the ultimate ideal method is to ban the removal of background messages.

Attached: Some tried but failed records

1) use SetStyle

Online has said that use the SetStyle function to set the parameters of the control, specifically:

SetStyle (Controlstyles.userpaint | Controlstyles.allpaintinginwmpaint | Controlstyles.optimizeddoublebuffer, True);

These three option parameters the latter is dependent on the former, must coexist, otherwise invalid. And the function itself is protected, so first you need to inherit a control and then use it.

This goal is consistent with the correct solution before, and it is also forbidden to clear the background and turn on double buffering, but you need to use the user drawing option, and all is drawn by the user. This requires you to implement the entire drawing of the control, more cumbersome. So this method is not completely infeasible, but requires extra work, not recommended. I didn't use it either.

2) Use beginupdate and endupdate

This pair of actions has a good effect on scenarios that require bulk manipulation of the update control, such as a large number of nodes being added in bulk during initialization. The downside is that you can't update it instantly. Therefore, for frequent update nodes and want to immediately reflect the situation to the interface is not applicable. If you use and do not disable the clear interface message, the control will appear to flicker, and the white background is dominated, the content is almost invisible (this depends on the degree of frequency). Because the interface updates are done at endupdate, too many operations cause the endupdate to block for too long, and are emptied before the update, causing the interface to appear to be in a blank state for a long time.

3) Use the Controlstyles.enablenotifymessage option

The function of this option is consistent with the correct solution. Use this method:

SetStyle (Controlstyles.enablenotifymessage, true);

protected override void Onnotifymessage (Message m)

{

Write a filter message code here

}

But the actual experiment showed no effect, do not know what reason, no scrutiny.

Solutions for flashing problems with several C # controls (GO)

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.