DockPanel的一点点改进
2008-08-26 13:23
183 查看
1、当双击Tab时,原先是直接把当前Tab所表示的这个窗体,从主窗体的框架上分离现来,成为一个浮动的窗体。这不是我想要的,我把它改成了双击关闭。
在DockPaneStripBase的WndProc方法里,对于左键双击消息重新作了处理(下面注释掉的一行是原先的写法,它下面那行是改的):
[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;
if (content.DockHandler.HideOnClose)
content.DockHandler.Hide();
else
content.DockHandler.Close();
}
return;
}
base.WndProc(ref m);
return;
}
2、很多窗体都在Tab中有个右键菜单,右击的里面有关闭,所以最好继承一下DockContent,让其它窗体只要继承这个就有了这个右键菜单
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WeifenLuo.WinFormsUI.Docking
{
public class DockContentEx : WeifenLuo.WinFormsUI.Docking.DockContent
{
public DockContentEx()
{
ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
ToolStripMenuItem tsmiClose = new System.Windows.Forms.ToolStripMenuItem();
//
// cms
//
tsmiClose.Name = "cms";
tsmiClose.Size = new System.Drawing.Size(98, 22);
tsmiClose.Text = "关闭";
tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click);
//
// tsmiClose
//
cms.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
tsmiClose});
cms.Name = "tsmiClose";
cms.Size = new System.Drawing.Size(99, 26);
this.TabPageContextMenuStrip = cms;
}
private void tsmiClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
在DockPaneStripBase的WndProc方法里,对于左键双击消息重新作了处理(下面注释掉的一行是原先的写法,它下面那行是改的):
[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;
if (content.DockHandler.HideOnClose)
content.DockHandler.Hide();
else
content.DockHandler.Close();
}
return;
}
base.WndProc(ref m);
return;
}
2、很多窗体都在Tab中有个右键菜单,右击的里面有关闭,所以最好继承一下DockContent,让其它窗体只要继承这个就有了这个右键菜单
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WeifenLuo.WinFormsUI.Docking
{
public class DockContentEx : WeifenLuo.WinFormsUI.Docking.DockContent
{
public DockContentEx()
{
ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
ToolStripMenuItem tsmiClose = new System.Windows.Forms.ToolStripMenuItem();
//
// cms
//
tsmiClose.Name = "cms";
tsmiClose.Size = new System.Drawing.Size(98, 22);
tsmiClose.Text = "关闭";
tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click);
//
// tsmiClose
//
cms.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
tsmiClose});
cms.Name = "tsmiClose";
cms.Size = new System.Drawing.Size(99, 26);
this.TabPageContextMenuStrip = cms;
}
private void tsmiClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
相关文章推荐
- [转]WeifenLuo.WinFormsUI.Docking——DockPanel的一点点改进
- (转)DockPanel的一点点改进
- 对groupbox的一点点改进
- 有关Floyd相关算法的一点点改进
- CSDN博客的一些问题(友好的吐槽)--后记,有一点点改进
- CSDN博客的一些问题(友好的吐槽)--后记,有一点点改进
- 技术一点点的改进给我们带来很大的方便
- 项目改进:引入基础类
- 调查:听取当前用户的意见(并改进),是为什么?
- 使用 Forms 身份验证的一点点心得
- 0203 朴素的模式匹配,改进
- Ajax 改造,第 2 部分: 使用 jQuery、Ajax、工具提示和 lightbox 改进现有站点
- linux2.6.28内核对页面置换算法的改进--理论
- 2.6.29内核中对vmscan的一个改进
- AutoCAD Map3D 改进意见征集活动
- 1633 Fibonacci 【改进】
- Gmail 升级,大大改进打开新窗口的速度
- 每天进步一点点
- C4.5主要改进
- 一点点科学哲学(A Bit of Scientific Philosophy)