Click here to monitor SSC

James Moore

Divisional Manager for SQL Tools - Red Gate Software

Freeze Painting

Published Saturday, October 29, 2005 11:03 AM

We use a large amount of thrid party controls in our UIs however some of these do not always behave as expected and ignore BeginInit/BeginUpdate/SuspendLayout.

I came across this work around for this problem the other day:

 

        [DllImport("User32")] 
        private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        int m_paintFrozen = 0;
        private bool FreezePainting 
        { 

            get { return m_paintFrozen > 0; }

            set 
           
                if (value && IsHandleCreated && this.Visible
               
                    if (0 == m_paintFrozen++) 
                   
                        SendMessage(Handle, WM_SETREDRAW, 0, 0); 
                   
               

                if (!value
               
                    if (m_paintFrozen == 0) 
                   
                        return
                    }


                    if (0 == --m_paintFrozen
                    
                        SendMessage(Handle, WM_SETREDRAW, 1, 0); 
                        Invalidate(true); 
                   
               
           
        }

 

You can then force a control to stop painting by setting FreezePainting to true, just remember to do it inside of a

try - finally block so you are sure you turn it back on..

 

by James

Comments

No Comments
New Comments to this post are disabled
Latest articles
Checking Out SQL Backup Pro 7’s New Automatic Backup Verification
 Wouldn't it be great to offload the daily chore of checking the integrity of your production... Read more...

Chuck Lathrope: DBA of the Day
 Chuck Lathrope was a finalist for the Exceptional DBA of the Year award in 2009. We contacted him to... Read more...

Backups, What Are They Good For?
 Pixar recently confessed, in an engaging video, that Toy Story 2 was almost lost due to a bad backup,... Read more...

C# Async: What is it, and how does it work?
 The biggest new feature in C#5 is Async, and its associated Await (contextual) keyword. Anybody who is... Read more...

SQL Server 2012 AlwaysOn
 SQL Server AlwaysOn provides a high-availability and Disaster-recovery solution for SQL Server 2012. It... Read more...