框架提供关闭当前窗体,除此之外全部关闭窗体的功能(弹出菜单)
实现一个增值功能, 在xtraTabbedMdiManager组件TabPage标题上右鍵弹出关闭当前窗体的菜单.
框架提供关闭当前窗体,除此之外全部关闭窗体的功能(弹出菜单)
private void menuCloseThis_Click(object sender, EventArgs e)
{//关闭当前窗体
int i = xtraTabbedMdiManager1.Pages.IndexOf(xtraTabbedMdiManager1.SelectedPage);//当前窗体的序号
Form form = xtraTabbedMdiManager1.SelectedPage.MdiChild;
if (form is frmModuleContainer) { }
else
{
form.Close();//不关闭模块主窗体
if (xtraTabbedMdiManager1.Pages.Count - 1 >= i)
{
//显示相邻的窗体
xtraTabbedMdiManager1.SelectedPage = xtraTabbedMdiManager1.Pages[i];
}
}
}
private void menuCloseAll_Click(object sender, EventArgs e)
{//除此之外全部关闭
Form currentForm = xtraTabbedMdiManager1.SelectedPage.MdiChild;//当前窗体
IList list = new ArrayList();
foreach (XtraMdiTabPage p in xtraTabbedMdiManager1.Pages) list.Add(p.MdiChild);//构建窗体列表
foreach (Form form in list)
{
//不关闭当前窗体,模块主窗体及模块容器窗体
if ((currentForm == form) || (form is frmModuleContainer) || (form is IModuleBase)) continue;
form.Close();
}
}
private void xtraTabbedMdiManager1_MouseUp(object sender, MouseEventArgs e)
{
//点左键无效, 必须是点右键弹出菜单
if (e.Button != MouseButtons.Right) return;
menuCloseThis.Enabled = !(xtraTabbedMdiManager1.SelectedPage.MdiChild is frmModuleContainer);//模块主窗体禁止关闭
BaseTabHitInfo hint = xtraTabbedMdiManager1.CalcHitInfo(e.Location);
//点击有效,且点击在TabPage标题上
if (hint.IsValid && (hint.Page != null))
{
//有效子窗体
if (xtraTabbedMdiManager1.SelectedPage.MdiChild != null)
{
Point p = xtraTabbedMdiManager1.SelectedPage.MdiChild.PointToScreen(e.Location);
menuStripCloseForm.Show(p); //显示弹出菜单
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898