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] -
.NET | Windows Forms
Navigation
Archive
<February 2006>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
2627281234
567891011
About the author/Disclaimer

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

© Copyright 2010
Christoph De Baene
Sign In
Statistics
Total Posts: 176
This Year: 2
This Month: 0
This Week: 0
Comments: 249
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene