布局控件"WeifenLuo.WinFormsUI.Docking"是一个非常棒的开源控件,用过的人都深有体会,该控件之强大、美观、不亚于商业控件。而且控件使用也是比较简单的。本文介绍如何给 WeifenLuo.WinFormsUI.Docking 控件的标签文档添加双击标题自动关闭事件,方法很简单,只需稍稍修改 WeifenLuo.WinFormsUI.Docking 的代码即可。
在DockPaneStripBase的WndProc方法里,对于左键双击消息重新作了处理,我们先找到这段代码,位于 DockPaneStripBase.cs 类文件中,原始代码如下:
- [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
- {
- base.WndProc(ref m);
- int index = HitTest();
- if (DockPane.DockPanel.AllowEndUserDocking && index != -1)
- {
- IDockContent content = Tabs[index].Content;
- if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown)
- content.DockHandler.IsFloat = !content.DockHandler.IsFloat;
- }
- return;
- }
- base.WndProc(ref m);
- return;
- }
下面我们只要稍作修改即可,改后的代码:
- [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
- {
- base.WndProc(ref m);
- int index = HitTest();
- if (DockPane.DockPanel.AllowEndUserDocking && index != -1)
- {
- IDockContent content = Tabs[index].Content;
- if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown)
- content.DockHandler.IsFloat = !content.DockHandler.IsFloat;
- //以下两行代码由宜城小子于2010-09-28添加
- //实现双击文档选项卡自动关闭
- else
- content.DockHandler.Close();
- }
- return;
- }
- base.WndProc(ref m);
- return;
- }
加下划线的那两行代码就是了,呵呵很简单吧!