protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (printDocument != null)
         {
             printDocument.BeginPrint -= new PrintEventHandler(this.BeginPrint);
             printDocument.PrintPage  -= new PrintPageEventHandler(this.PrintPage);
             printDocument             = null;
         }
         Document.UndoStack.ClearAll();
         Document.UpdateCommited -= new EventHandler(CommitUpdateRequested);
         if (textAreaPanel != null)
         {
             if (secondaryTextArea != null)
             {
                 secondaryTextArea.Dispose();
                 textAreaSplitter.Dispose();
                 secondaryTextArea = null;
                 textAreaSplitter  = null;
             }
             if (primaryTextArea != null)
             {
                 primaryTextArea.Dispose();
             }
             textAreaPanel.Dispose();
             textAreaPanel = null;
         }
     }
     base.Dispose(disposing);
 }
        public void Split()
        {
            if (secondaryTextArea == null)
            {
                primaryTextArea.Controls.Remove(primaryTextArea.splitterButton);

                secondaryTextArea        = new TextAreaControl(this);
                secondaryTextArea.Dock   = DockStyle.Bottom;
                secondaryTextArea.Height = Height / 2;

                secondaryTextArea.Controls.Remove(secondaryTextArea.splitterButton);
                secondaryTextArea.TextArea.GotFocus += delegate {
                    SetActiveTextAreaControl(secondaryTextArea);
                };
                TextEditorProperties.IsSplit    = true;
                textAreaSplitter                = new Splitter();
                textAreaSplitter.BorderStyle    = BorderStyle.None;
                textAreaSplitter.Height         = 8;
                textAreaSplitter.Dock           = DockStyle.Bottom;
                textAreaSplitter.MinExtra       = 0;
                textAreaSplitter.MinSize        = 0;
                textAreaSplitter.DoubleClick   += TextAreaSplitter_DoubleClick;
                textAreaSplitter.SplitterMoved += TextAreaSplitter_OnSplitterMoved;
                textAreaPanel.Controls.Add(textAreaSplitter);
                textAreaPanel.Controls.Add(secondaryTextArea);
                InitializeTextAreaControl(secondaryTextArea);
                secondaryTextArea.OptionsChanged();
            }
            else
            {
                TextEditorProperties.IsSplit = false;
                primaryTextArea.Controls.Add(primaryTextArea.splitterButton);
                primaryTextArea.SetScrollBarBounds();
                SetActiveTextAreaControl(primaryTextArea);

                textAreaPanel.Controls.Remove(secondaryTextArea);
                textAreaPanel.Controls.Remove(textAreaSplitter);

                secondaryTextArea.Dispose();
                textAreaSplitter.Dispose();
                secondaryTextArea = null;
                textAreaSplitter  = null;
            }
        }