Avoid multiple control forms flashing demo

Source: Internet
Author: User
[Supplement] avoid multi-control form flashing demo preference: http://www.cnblogs.com/lovesanni/archive/2009/09/08/1562844.html

As mentioned above, the beginupdateinternal and endupdateinternal methods of the control class are imitated to encapsulate the basic classes applicable to each control. Code Right

1 Class Avoidcontrolflicker
2 {
3 Private   Int _ Paintfrozen;
4
5 Public   Void Freezepainting (control tofreezecontrol, Bool Istofreeze)
6 {
7 If ( Null   = Tofreezecontrol)
8 Throw   New Argumentnullexception ( " Tofreezecontrol " );
9
10 If (Istofreeze && Tofreezecontrol. ishandlecreated && Tofreezecontrol. Visible)
11 {
12 If ( 0   = _ Paintfrozen ++ )
13 {
14Nativemethods. sendmessage (tofreezecontrol. Handle, nativeconsts. wm_setredraw,0,0);
15}
16 }
17 If ( ! Istofreeze)
18 {
19 If ( 0   = _ Paintfrozen) Return ;
20 If ( 0   =   -- _ Paintfrozen)
21 {
22 Nativemethods. sendmessage (tofreezecontrol. Handle, nativeconsts. wm_setredraw, 1 , 0 );
23 Tofreezecontrol. invalidate ( True );
24 }
25 }
26 }
27 }

The code is very simple. When you need to "freeze" The control object, Windows sends the wm_setredraw event to the control. If you do not need to "freeze", send the event again and change the parameter, note that
1. Add a counter to prevent multiple sending of the same message
2. after the control is restored, force the control to be repainted, that is, 23 lines of code: tofreezecontrol. invalidate (true); because the invalidate method is provided by the control class itself, it can be used directly. The true parameter indicates that all child controls of the control are also re-painted, false indicates that only the user is repainted.

How can I write an external form? (A form that does not belong to the process, or a form object that cannot be accessed directly). To use the Windows taskbar, You need to obtain its handle first:

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> intptr taskbarhandle = nativemethods. findshortwa ( " shell_traywnd " , "" );

after obtaining the handle, you can send a Windows message to it:

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> nativemethods. sendmessage (taskbarhandle, nativeconsts. wm_setredraw, 0 , 0 ); // disable repainting

When "unfreeze" is required: Nativemethods. sendmessage (taskbarhandle, nativeconsts. wm_setredraw,1,0);
Nativemethods. redrawwindow (taskbarhandle, intptr. Zero, intptr. Zero, nativeconsts. wm_ncpaint );//Force redraw

As for the Demo code, it is very simple. I have created 225 button objects in the resize event of the form. If the avoidcontrolflicker class is not applied, it can be seen that there is a large blank area when the form is scaled, the actual effect is compared with two screenshots in the demo compressed package. If you don't talk much about it, click here to download it.

PS. based on my test results, if re-painting is disabled on the taskbar on Vista, but the re-painting is not enabled, the result is very tragic: After clicking the mouse, there is no response, but you can click the Start Menu; I am not sure about xp. I cannot find the XP environment for the time being.

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.