WeifenLuo.WinFormsUI.Docking添加关闭功能
标签:winform style blog http 使用 os
/******************************************************************
* 创建人:HTL
* 创建时间:2014-7-8 15:37:20
* 说明:WinFormsUI添加右键关闭菜单
* Email:huangyuan413026@163.com
*******************************************************************/
usingSystem;
usingWeifenLuo.WinFormsUI.Docking;
namespace WinForm.BaseForms
{
///
/// WinFormsUI添加右键关闭菜单
/// 让其它窗体只要继承这个就有了这个右键菜单,即可关闭窗体
///
publicclassDockContentEx:DockContent
{
//在Tag列表上添加右键关闭菜单
publicDockContentEx()
{
System.Windows.Forms.ContextMenuStrip cms =newSystem.Windows.Forms.ContextMenuStrip();
cms.Items.AddRange(newSystem.Windows.Forms.ToolStripItem[]{
newSystem.Windows.Forms.ToolStripMenuItem("关闭", null, tsmiClose_Click,"tsmiClose")
,newSystem.Windows.Forms.ToolStripMenuItem("关闭其他", null, tsmiClose_Click,"tsmiOtherClose")
,newSystem.Windows.Forms.ToolStripMenuItem("全部关闭", null, tsmiClose_Click,"tsmiAllClose")
});
//将右键菜单绑定到DockContent的TabPage上
this.TabPageContextMenuStrip= cms;
//也可以使用这种方式
//this.TabPageContextMenu=newSystem.Windows.Forms.ContextMenu();
}
//菜单事件
privatevoid tsmiClose_Click(object sender,EventArgs e)
{
System.Windows.Forms.ToolStripMenuItem _tsmt = sender as System.Windows.Forms.ToolStripMenuItem;
if(_tsmt == null)return;
switch(_tsmt.Name)
{
case"tsmiClose":this.Close();break;
case"tsmiAllClose":HideOrCloseFrom(true);break;
case"tsmiOtherClose":HideOrCloseFrom();break;
default:break;
}
}
///
/// 隐藏其他窗体
///
voidHideOrCloseFrom()
{
HideOrCloseFrom(false,false);
}
///
/// 隐藏窗体
///
/// 隐藏所有还是其他窗体
voidHideOrCloseFrom(bool isAll)
{
HideOrCloseFrom(isAll,false);
}
///
/// 关闭还是隐藏窗体
///
/// 是否是所有窗体,还是除当前窗体以外的其他窗体
/// 是否是关闭窗体,默认为隐藏窗体
privatevoidHideOrCloseFrom(bool isAll,bool isClose)
{
DockContentCollection contents =DockPanel.Contents;
for(int i =0; i
/// 关闭或隐藏当前窗体
/// 仅DockState状态跟当前的DockState状态相同的窗体
///
/// 当前窗体对象
voidHideOrCloseFrom(DockContentHandler content,bool isClose)
{
if(content == null || content.DockState!=this.DockState)return;
if(isClose)
content.Close();
elseif(!content.IsHidden)
content.Hide();
}
}
}
主要是利用WinFormsUI的TabPageContextMenuStrip属性或TabPageContextMenu绑定自定义的右键菜单来实现的
//将右键菜单绑定到DockContent的TabPage上
this.TabPageContextMenuStrip= cms;
//也可以使用这种方式
//this.TabPageContextMenu = new System.Windows.Forms.ContextMenu();
http://www.cnblogs.com/luomingui/p/3329763.html
WinFormsUI开源地址:https://github.com/dockpanelsuite/dockpanelsuite
http://blog.yotuo.net/post/2010/09/WeifenLuo.WinFormsUI.Docking_doubleclick_close.html
MSDN MenuItem 类:http://msdn.microsoft.com/zh-cn/library/System.Windows.Forms.MenuItem(v=vs.80).aspx
MSDN ToolStripMenuItem 类:http://msdn.microsoft.com/zh-cn/library/system.windows.forms.toolstripmenuitem(v=vs.80).aspx
WeifenLuo.WinFormsUI.Docking添加关闭功能,搜素材,soscw.com
WeifenLuo.WinFormsUI.Docking添加关闭功能
标签:winform style blog http 使用 os
原文地址:http://www.cnblogs.com/huangtailang/p/ca957a9314ed0a9543f6399a51d32c28.html
评论