/// <summary>
/// 关闭所有窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menu_Window_CloseAll_Click(object sender, EventArgs e)
{
CloseAllDocuments();
}
public void CloseAllDocuments()
{
if (dockPanel1.DocumentStyle==DocumentStyle.SystemMdi)
{
foreach (Form form in MdiChildren)
{
form.Close();
}
}
else
{
IDockContent[] documents=dockPanel1.DocumentsToArray();
foreach (IDockContent content in documents)
{
content.DockHandler.Close();
}
}
}
/// <summary>
/// 关闭其他窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menu_Window_CloseOther_Click(object sender, EventArgs e)
{
if (dockPanel1.DocumentStyle == DocumentStyle.SystemMdi)
{
Form activeMdi = ActiveMdiChild;
foreach (Form form in MdiChildren)
{
if (form != activeMdi)
{
form.Close();
}
}
}
else
{
foreach (IDockContent document in dockPanel1.DocumentsToArray())
{
if (!document.DockHandler.IsActivated)
{
document.DockHandler.Close();
}
}
}
}
/// <summary>
/// 找到窗体
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
private DockContent FindDocument(string text)
{
if (dockPanel1.DocumentStyle == DocumentStyle.SystemMdi)
{
foreach (Form form in MdiChildren)
{
if (form.Text == text)
{
return form as DockContent;
}
}
return null;
}
else {
foreach (DockContent content in dockPanel1.Documents)
{
if (content.DockHandler.TabText==text)
{
return content;
}
}
return null;
}
}
public DockContent ShowContent(string caption, Type formType)
{
DockContent frm = FindDocument(caption);
if (frm==null)
{
// frm = ChildWinManagement.LoadMdiForm(Portal.gc.MainDialog, formType) as DockContent;
}
frm.Show(this.dockPanel1);
frm.BringToFront();//将控件带到前面
return frm;
}