Skip to content
This repository
Browse code

#78 - Fix ObjectDisposedException in sample

When loading from XML the explicitly referenced controls were not being
recreated (like the toolbox, etc; where there is a private member
holding a reference to the form).  Solution is to recreate these forms
before attempting to load from XML, just as load from code is doing.
  • Loading branch information...
commit 569ee5e7c0df4f2cb5097940300a3e0dc54dce52 1 parent 216e0de
authored March 10, 2013

Showing 1 changed file with 19 additions and 11 deletions. Show diff stats Hide diff stats

  1. 30  DockSample/MainForm.cs
30  DockSample/MainForm.cs
@@ -14,19 +14,20 @@ public partial class MainForm : Form
14 14
     {
15 15
         private bool m_bSaveLayout = true;
16 16
         private DeserializeDockContent m_deserializeDockContent;
17  
-        private DummySolutionExplorer m_solutionExplorer = new DummySolutionExplorer();
18  
-        private DummyPropertyWindow m_propertyWindow = new DummyPropertyWindow();
19  
-        private DummyToolbox m_toolbox = new DummyToolbox();
20  
-        private DummyOutputWindow m_outputWindow = new DummyOutputWindow();
21  
-        private DummyTaskList m_taskList = new DummyTaskList();
  17
+        private DummySolutionExplorer m_solutionExplorer;
  18
+        private DummyPropertyWindow m_propertyWindow;
  19
+        private DummyToolbox m_toolbox;
  20
+        private DummyOutputWindow m_outputWindow;
  21
+        private DummyTaskList m_taskList;
22 22
 
23 23
         public MainForm()
24 24
         {
25 25
             InitializeComponent();
26 26
 
  27
+            CreateStandardControls();
  28
+
27 29
             showRightToLeft.Checked = (RightToLeft == RightToLeft.Yes);
28 30
             RightToLeftLayout = showRightToLeft.Checked;
29  
-            m_solutionExplorer = new DummySolutionExplorer();
30 31
             m_solutionExplorer.RightToLeftLayout = RightToLeftLayout;
31 32
             m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
32 33
         }
@@ -423,11 +424,7 @@ private void menuItemLayoutByCode_Click(object sender, System.EventArgs e)
423 424
 
424 425
             CloseAllDocuments();
425 426
 
426  
-            m_solutionExplorer = new DummySolutionExplorer();
427  
-            m_propertyWindow = new DummyPropertyWindow();
428  
-            m_toolbox = new DummyToolbox();
429  
-            m_outputWindow = new DummyOutputWindow();
430  
-            m_taskList = new DummyTaskList();
  427
+            CreateStandardControls();
431 428
 
432 429
             m_solutionExplorer.Show(dockPanel, DockState.DockRight);
433 430
             m_propertyWindow.Show(m_solutionExplorer.Pane, m_solutionExplorer);
@@ -447,6 +444,15 @@ private void menuItemLayoutByCode_Click(object sender, System.EventArgs e)
447 444
             dockPanel.ResumeLayout(true, true);
448 445
         }
449 446
 
  447
+        private void CreateStandardControls()
  448
+        {
  449
+            m_solutionExplorer = new DummySolutionExplorer();
  450
+            m_propertyWindow = new DummyPropertyWindow();
  451
+            m_toolbox = new DummyToolbox();
  452
+            m_outputWindow = new DummyOutputWindow();
  453
+            m_taskList = new DummyTaskList();
  454
+        }
  455
+
450 456
         private void menuItemLayoutByXml_Click(object sender, System.EventArgs e)
451 457
         {
452 458
             dockPanel.SuspendLayout(true);
@@ -454,6 +460,8 @@ private void menuItemLayoutByXml_Click(object sender, System.EventArgs e)
454 460
             // In order to load layout from XML, we need to close all the DockContents
455 461
             CloseAllContents();
456 462
 
  463
+            CreateStandardControls();
  464
+
457 465
             Assembly assembly = Assembly.GetAssembly(typeof(MainForm));
458 466
             Stream xmlStream = assembly.GetManifestResourceStream("DockSample.Resources.DockPanel.xml");
459 467
             dockPanel.LoadFromXml(xmlStream, m_deserializeDockContent);

0 notes on commit 569ee5e

Please sign in to comment.
Something went wrong with that request. Please try again.