void combinedHostingForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            CombinedHostingForm form = sender as CombinedHostingForm;

            if (form.ContainedControl == null)
            {
                _floatingFormsControls.RemoveByKey(form);
                return;
            }

            // Unsubscribe events.
            form.ResizeBegin -= new EventHandler(combinedHostingForm_ResizeBegin);
            form.ResizeEnd   -= new EventHandler(combinedHostingForm_ResizeEnd);

            form.FormClosing -= new FormClosingEventHandler(combinedHostingForm_FormClosing);
            form.Activated   -= new EventHandler(combinedHostingForm_Activated);

            if (e.CloseReason != CloseReason.UserClosing)
            {// We are doing a major application close, do not ask anything.
                // Persist data form this form since it is being closed and will no longer have it properly assigned.
                PersistControlData(form.ContainedControl, form);
                CommonBaseControl control = form.ContainedControl;
                form.ContainedControl = null;

                // Clear from list of internal controls.
                DoRemoveControl(control);

                return;
            }


            DialogResult result = MessageBox.Show("Remove component?" + Environment.NewLine + "+ Click [Yes] to Remove" + Environment.NewLine + "- Click [No] to Send to Tabbed", "Open Forex Platform", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {// Remove.
                CommonBaseControl containedControl = form.ContainedControl;
                form.ContainedControl = null;
                RemoveControl(containedControl);
            }
            else if (result == DialogResult.No)
            {// Send to tabbed.
                _floatingFormsControls.RemoveByKey(form);
                form.Controls.Clear();
                AddTabbedControl(form.ContainedControl);
            }
            else if (result == DialogResult.Cancel)
            {// Keep it unchanged.
                e.Cancel = true;
            }
        }
        void combinedHostingForm_ResizeEnd(object sender, EventArgs e)
        {
            CombinedHostingForm form = (CombinedHostingForm)sender;

            foreach (CombinedHostingForm hostingForm in _floatingFormsControls.Keys)
            {
                //hostingForm.ContainedControl.Visible = true;
                hostingForm.Opacity = 1;
            }

            DockStyle?dockStyle = dragContainerControl.DoEndDrag(form.ContainedControl, Cursor.Position);

            if (dockStyle.HasValue)
            {
                AddWorkspaceControl(form.ContainedControl, dockStyle.Value, Point.Empty);
                form.ContainedControl = null;
                form.Close();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        /// <param name="location">Location to float to, in screen coordinates.</param>
        /// <param name="newWindow"></param>
        public CombinedHostingForm SetControlFloating(CommonBaseControl control)
        {
            DoRemoveControl(control);

            CombinedHostingForm form = new CombinedHostingForm(control);

            _floatingFormsControls.Add(form, control);

            form.Location         = Cursor.Position;
            form.ResizeBegin     += new EventHandler(combinedHostingForm_ResizeBegin);
            form.LocationChanged += new EventHandler(combinedHostingForm_LocationChanged);
            //form.MdiParent = this.ParentForm;
            form.ResizeEnd   += new EventHandler(combinedHostingForm_ResizeEnd);
            form.FormClosing += new FormClosingEventHandler(combinedHostingForm_FormClosing);
            form.Activated   += new EventHandler(combinedHostingForm_Activated);

            form.ShowInTaskbar = true;
            form.Show(this.ParentForm);
            form.BringToFront();

            UpdateUI();

            return(form);
        }
        /// <summary>
        ///
        /// </summary>
        public void AddControl(CommonBaseControl control)
        {
            Point?location = null;
            Size? size     = null;

            if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Size"))
            {
                size = control.PersistenceData.GetValue <Size>("combinedContainer.Size");
            }

            if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Location"))
            {
                location = control.PersistenceData.GetValue <Point>("combinedContainer.Location");
            }

            if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Floating"))
            {
                CombinedHostingForm form = SetControlFloating(control);
                if (location.HasValue)
                {
                    form.Location = location.Value;
                }

                // Sometimes persistence may be wrong, so make sure to bring control to view when added.
                form.Left = Math.Max(form.Left, 0);
                form.Top  = Math.Max(form.Top, 0);

                form.Left = Math.Min(Screen.PrimaryScreen.WorkingArea.Width, form.Left);
                form.Top  = Math.Min(Screen.PrimaryScreen.WorkingArea.Height, form.Top);

                form.Width  = Math.Max(form.Width, 200);
                form.Height = Math.Max(form.Height, 150);

                if (size.HasValue)
                {
                    form.Size = size.Value;
                }
            }
            else if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Tabbed"))
            {
                AddTabbedControl(control);
            }
            else if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Docked") &&
                     control.PersistenceData.ContainsValue("combinedContainer.Guid"))
            {
                Guid        guid        = control.PersistenceData.GetValue <Guid>("combinedContainer.Guid");
                DragControl dragControl = dragContainerControl.GetDragControlByGuid(guid);
                if (dragControl == null)
                {
                    SystemMonitor.OperationError("Guid drag control not found. Using a default new one.");
                    AddTabbedControl(control);
                }
                else
                {// Reuse the existing drag control and place the new control inside it.
                    SetControlToDragControl(control, dragControl, Point.Empty);
                    dragControl.Visible = true;
                }
            }
            else
            {// By default add tabbed.
                AddTabbedControl(control);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="control"></param>
        /// <param name="location">Location to float to, in screen coordinates.</param>
        /// <param name="newWindow"></param>
        public CombinedHostingForm SetControlFloating(CommonBaseControl control)
        {
            DoRemoveControl(control);

            CombinedHostingForm form = new CombinedHostingForm(control);
            _floatingFormsControls.Add(form, control);

            form.Location = Cursor.Position;
            form.ResizeBegin += new EventHandler(combinedHostingForm_ResizeBegin);
            form.LocationChanged += new EventHandler(combinedHostingForm_LocationChanged);
            //form.MdiParent = this.ParentForm;
            form.ResizeEnd += new EventHandler(combinedHostingForm_ResizeEnd);
            form.FormClosing += new FormClosingEventHandler(combinedHostingForm_FormClosing);
            form.Activated += new EventHandler(combinedHostingForm_Activated);

            form.ShowInTaskbar = true;
            form.Show(this.ParentForm);
            form.BringToFront();

            UpdateUI();

            return form;
        }