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
Saturday, February 25, 2006 1:19:29 PM (Romance Standard Time, UTC+01:00)
p0l, love the tip! I also want to add that if an exception occurs however in the method calls to the base class that you will not pass the FreezePaintingOff() call, it might be better to wrap the calls in a try...finally block for debugging purposes.
Sunday, February 26, 2006 6:26:17 PM (Romance Standard Time, UTC+01:00)
Good point! I've updated the code
Thursday, March 08, 2007 2:03:52 AM (Romance Standard Time, UTC+01:00)
I love this xt.It's so great.
But I have another problem.I'v added some views into a deckworkspace,then minimize the form,when I click the revert or maximize button,there will be a shuffle in the form.I don't know how to solve it.
HH
Wednesday, October 01, 2008 4:41:00 PM (Romance Daylight Time, UTC+02:00)
I have an unrelated problem. I have two views sharing one DeckWorkspace. Tabbing through the controls on the currently active view also tabs through the controls on the underlying inactive view. Has anyone noticed this?
Richard Stuppi
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Navigation
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
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: 283
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene