Hi Kenneth,
In this scenario the auto detected child form is handled like a document window and its
Close action disposes it. You can change this behavior by handling the
DockWindowAdded event. Consider the sample below:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Docking;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private RadDock radDock = new RadDock();
private RadButton radButton = new RadButton();
private ToolWindow toolWindow = new ToolWindow("My Tool");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
radDock.Dock = DockStyle.Fill;
this.Controls.Add(radDock);
this.IsMdiContainer = true;
this.radDock.AutoDetectMdiChildren = true;
this.radDock.DockWindowAdded += new DockWindowEventHandler(radDock_DockWindowAdded);
Form form = new Form();
form.Text = "My Form1";
form.MdiParent = this;
form.Show();
form = new Form();
form.Text = "My Form2";
form.MdiParent = this;
form.Show();
form = new Form();
form.Text = "My Form3";
form.MdiParent = this;
form.Show();
this.radDock.DockWindow(toolWindow, DockPosition.Left);
radButton.Text = "Show all windows";
radButton.Click += new EventHandler(radButton_Click);
toolWindow.Controls.Add(radButton);
}
void radDock_DockWindowAdded(object sender, DockWindowEventArgs e)
{
if (e.DockWindow.DockState == DockState.TabbedDocument && e.DockWindow is HostWindow)
{
Form form = e.DockWindow.Controls[0] as Form;
ToolWindow toolWindow = new ToolWindow(form.Text);
toolWindow.Controls.Add(form);
toolWindow.AllowedDockState = AllowedDockState.TabbedDocument | AllowedDockState.Hidden;
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.Dock = DockStyle.Fill;
this.radDock.AddDocument(toolWindow);
toolWindow.CloseAction = DockWindowCloseAction.Hide;
e.DockWindow.CloseAction = DockWindowCloseAction.CloseAndDispose;
e.DockWindow.Close();
}
}
void radButton_Click(object sender, EventArgs e)
{
IEnumerable<DockWindow> windows = this.radDock.GetWindows<DockWindow>();
foreach (var item in windows)
{
if (item.DockState == DockState.Hidden && item.Controls.Count > 0 && item.Controls[0] is Form)
{
this.radDock.DisplayWindow(item);
}
}
}
}
}
Please, feel free to contact us, if you have further questions.
Regards,
Julian Benkov
the Telerik team