Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Suppressing paint

Hi

I have an mdi form with many dockpanels. Is there some way I can do something with the main form so that none of the child windows will be painted? Something like .BeginUpdate and .EndUpdate that is used for ListView and TreeView. The problem is that I´m reading the child window locations from a file and I always see a flicker because first they appear in a default location and then i move them to the saved location. I have no way to hide them before I add them because they are created using a method .AddPanel in a third party component and that will always show them first in the default position.

Anyone?

frank
Thursday, May 05, 2005

Here's how it is done in Win32..

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_4i5h.asp

Don't know about the analagous function in .NET.

Michael H. Pryor (fogcreek)
Fog Creek Software
Thursday, May 05, 2005

PInvoke?

oMan
Thursday, May 05, 2005

This might help

http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=4628&ixReplies=0

Charles Reich
Thursday, May 05, 2005

Something like this will work by dropping down to Win32 level (which is *still* there).  (NOTE: Assumes that you've inherited from the control you want to stop painting on).

(NOTE: EndUpdate invalidates the parent -- if you only need to invalidate the control, subsitute "this" for "Parent").

    private const int WM_SETREDRAW = 11;  // 0x000B
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);
      public void BeginUpdate()
      {
        SendMessage( this.Handle, WM_SETREDRAW, 0, 0);
      }

      public void EndUpdate()
      {
        SendMessage( this.Handle, WM_SETREDRAW, 1, 0);
        Parent.Invalidate(true);
      }

BillT
Thursday, May 05, 2005

You should use LockWindowUpdate. It will stop all painting of the window until you unlock it.

//API Declaration
[System.Runtime.InteropServices.DllImport("user32.dll")] static extern Int32 LockWindowUpdate(Int32hwndLock);


private void SomeFunction()
{    
    //Lock the Window
    LockWindowUpdate(Form.Handle.ToInt32());            
    // Do stuff
                                    
    //Unlock the Window    
    LockWindowUpdate(0);
}

Marc
Monday, May 09, 2005

I don't LockWindowUpdate is what you want here. As per http://blogs.msdn.com/oldnewthing/search.aspx?q=lockwindowupdate&p=1 , LockWindowUpdate is not made for this. WM_SETREDRAW on  the other hand is.

Mike L.
Thursday, June 09, 2005

*  Recent Topics

*  Fog Creek Home