sharing about .NET and technology RSS 2.0
 Thursday, February 23, 2006

CAB is an application block for building smart clients in .NET 2.0 and contains proven practices for building complex UI forms with so called SmartParts and Workspaces. The DeckWorkspace enables you to show and hide controls and SmartParts in an overlapped manner with no visible frame.

If you switch between controls, you will notice that the controls are painted while there are initializing. During the loading you will see that there is some overlapping and it doesn't give you a professional user experience.

Therefore I extended the DeckWorkspace, so that the the controls are only redrawed when they are initialized. This can be done through the WM_SETREDRAW message. Note that this technique can also be used for other workspaces.

public class DeckWorkspaceEx: DeckWorkspace

   int freezePainting = 0;
   const int WM_SETREDRAW = 0xB;

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

   protected void FreezePaintingOn()
   {
      if (IsHandleCreated && this.Visible)
      {
         if (0 == freezePainting++)
         {
            SendMessage(Handle, WM_SETREDRAW, 0, 0);
         }
      }
   }

   protected void FreezePaintingOff()
   {
      if (freezePainting != 0)
      {
         if (0 == --freezePainting)
         {
            SendMessage(Handle, WM_SETREDRAW, 1, 0);
            Invalidate(true);
         }
      }
   }

   protected override void OnActivate(Control smartPart)
   {
      FreezePaintingOn();
      try 
      {
         base.OnActivate(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }

   protected override void OnClose(Control smartPart)
   {   
      FreezePaintingOn();
      try 
      {
         base.OnClose(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }

   protected override void OnHide(Control smartPart)
   {
      FreezePaintingOn();
      try 
      {
         base.OnHide(smartPart);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }   

   protected override void OnShow(Control smartPart, SmartPartInfo smartPartInfo)
   {
      FreezePaintingOn();
      try 
      {
         base.OnShow(smartPart, smartPartInfo);
      }
      finally 
      {
         FreezePaintingOff();
      }
   }
}

Thursday, February 23, 2006 1:14:56 AM (Romance Standard Time, UTC+01:00)  #    Comments [4] -

Navigation
Archive
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Christoph De Baene
Sign In
Statistics
Total Posts: 151
This Year: 22
This Month: 1
This Week: 0
Comments: 147
All Content © 2008, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene (delarou)