CAB: Closing a Window in a WindowWorkspace#

As some of you may have already figured out depending on how you close a window in a window workspace you will get two different results.  If you call Close(smartpart) on the workspace the smart gets removed from the form before it is disposed (this happens in the OnClose method).  If you just click the “X” on the form the view is allowed to be disposed.  To correct this I had the private method WindowFormClosed call the OnClose by changing to read the below:

  private void WindowFormClosed(object sender, WorkspaceEventArgs e)
  {
   Control smartPart = e.SmartPart as Control;

   if (smartPart != null)
    OnClose(smartPart);
  }

And then changed the OnClose to read:

 /// <summary>
  /// Closes the form where the smart part is being shown.
  /// </summary>
  protected override void OnClose(Control smartPart)
  {
   Form form = windowDictionary[smartPart];
   smartPart.Disposed -= ControlDisposed;

   // Remove the smartPart from the form to avoid disposing it.
   form.Controls.Remove(smartPart);

   form.Close();
   windowDictionary.Remove(smartPart);
   base.InnerSmartParts.Remove(smartPart);

   base.RaiseSmartPartClosed(smartPart);
  }

 

Sunday, January 15, 2006 6:43:25 PM (GMT Standard Time, UTC+00:00) #    Comments [0]  | 

 

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
All content © 2009, John Luif