(转) DockPanel 右键增加关闭,除此之外全部关闭的功能
在项目中新建一个class文件,代码如下:
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
{
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem 关闭ToolStripMenuItem;
private ToolStripMenuItem 全部关闭ToolStripMenuItem;
private ToolStripMenuItem 除此之外全部关闭ToolStripMenuItem;
private IContainer components; public DockContentEx()
{
//ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip();
//ToolStripMenuItem tsmiClose = new System.Windows.Forms.ToolStripMenuItem();
//ToolStripMenuItem tsmiCloseAll = new System.Windows.Forms.ToolStripMenuItem(); //tsmiClose.Name = "cms";
//tsmiClose.Size = new System.Drawing.Size(98, 22);
//tsmiClose.Text = "关闭";
//tsmiClose.Click += new System.EventHandler(this.tsmiClose_Click); //cms.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {tsmiClose});
//cms.Name = "tsmiClose";
//cms.Size = new System.Drawing.Size(99, 26); InitializeComponent();
this.TabPageContextMenuStrip = contextMenuStrip1;
} private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.关闭ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.除此之外全部关闭ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.全部关闭ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.关闭ToolStripMenuItem,
this.除此之外全部关闭ToolStripMenuItem,
this.全部关闭ToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.ShowImageMargin = false;
this.contextMenuStrip1.Size = new System.Drawing.Size(, );
//
// 关闭ToolStripMenuItem
//
this.关闭ToolStripMenuItem.Name = "关闭ToolStripMenuItem";
this.关闭ToolStripMenuItem.Size = new System.Drawing.Size(, );
this.关闭ToolStripMenuItem.Text = "关闭";
this.关闭ToolStripMenuItem.Click += new System.EventHandler(this.关闭ToolStripMenuItem_Click);
//
// 除此之外全部关闭ToolStripMenuItem
//
this.除此之外全部关闭ToolStripMenuItem.Name = "除此之外全部关闭ToolStripMenuItem";
this.除此之外全部关闭ToolStripMenuItem.Size = new System.Drawing.Size(, );
this.除此之外全部关闭ToolStripMenuItem.Text = "除此之外全部关闭";
this.除此之外全部关闭ToolStripMenuItem.Click += new System.EventHandler(this.除此之外全部关闭ToolStripMenuItem_Click);
//
// 全部关闭ToolStripMenuItem
//
this.全部关闭ToolStripMenuItem.Name = "全部关闭ToolStripMenuItem";
this.全部关闭ToolStripMenuItem.Size = new System.Drawing.Size(, );
this.全部关闭ToolStripMenuItem.Text = "全部关闭";
this.全部关闭ToolStripMenuItem.Click += new System.EventHandler(this.全部关闭ToolStripMenuItem_Click);
//
// DockContentEx
//
this.ClientSize = new System.Drawing.Size(, );
this.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.Name = "DockContentEx";
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false); } private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
} private void 除此之外全部关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
IDockContent[] documents = DockPanel.DocumentsToArray(); foreach (IDockContent content in documents)
{
if (!content.Equals(this))
{
content.DockHandler.Close();
}
}
} private void 全部关闭ToolStripMenuItem_Click(object sender, EventArgs e)
{
IDockContent[] documents = DockPanel.DocumentsToArray(); foreach (IDockContent content in documents)
{
content.DockHandler.Close();
}
}
}
}
其他准备以dockpanel方式打开的form都改为继承自上面这个DockPanelEx类
(转) DockPanel 右键增加关闭,除此之外全部关闭的功能的更多相关文章
- 如何让MFC程序关闭按钮失效,也无法右击任务栏关闭窗口来关闭?
如何让MFC程序关闭按钮失效,也无法右击任务栏关闭窗口来关闭,即右键任务栏的关闭窗口失效呢?很简单,有一个小窍门就是:响应IDCANCEL消息,具体实现如下: 首先定义消息映射:ON_BN_CLICK ...
- win7/8 关闭非正常关机的自动修复功能
win7/8 关闭非正常关机的自动修复功能 1.桌面右键新建一个文档文本,双击打开文件新建文本文档,复制以下命令到文本里面! bcdedit /set {default} bootstatuspoli ...
- 我为 Netty 贡献源码 | 且看 Netty 如何应对 TCP 连接的正常关闭,异常关闭,半关闭场景
欢迎关注公众号:bin的技术小屋,本文图片加载不出来的话可查看公众号原文 本系列Netty源码解析文章基于 4.1.56.Final版本 写在前面..... 本文是笔者肉眼盯 Bug 系列的第三弹,前 ...
- 如何让Visual Studio 清除最近打开项目 关闭上次未关闭的标签窗口
删除最近打开的文件: 打开HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\FileMRUList 删除最近打开的项目: 打开HKEY_CUR ...
- Sails 关闭自动路由 Automatic Routes 功能。
Sails 关闭自动路由 Automatic Routes 功能. Sails 中的路由两种:Custom Routes 和 Automatic Routes,自定义路由和自动路由.详见文档: Sai ...
- ExtJs4.2中Tab选项卡的右击关闭其它和关闭当前功能不准确的解决方法
一.ExtJs4.2中Tab选项卡的右击关闭其它和关闭当前功能不准确的解决方法 二.找到ux目录下的TabCloseMenu.js文件,将内容替换成下面代码. 三.代码: /** * Plugin f ...
- centos 关闭selinux 临时关闭selinux 报错 setenforce: setenforce() failed
关闭selinux的方法有两种:临时关闭和永久关闭. 查看selinux的状态:estatus [root@--- ~]# sestatus SELinux status: enabled SELin ...
- win7或win2008系统中,出现【已停止工作,联机检查解决方案并关闭该程序,关闭程序】解决方法!
win7或win2008系统中,出现[已停止工作,联机检查解决方案并关闭该程序,关闭程序]解决方法! 经过摸索,点击[控制面板]-[操作中心]-[更改操作中心设置]-[问题报告设置]-[从不检查解决方 ...
- Linux学习之设置联网,关闭防火墙,关闭selinux
桥接模式,给一台物理机,有自己独立的IP. boot分区,引导分区,系统启动,内核文件. swap分区,内存扩展分区.1.5或2倍.内存不够的时候,会写入其中.正常给8G或者16G就够了.不需要非要1 ...
随机推荐
- 正则表达式从右往左进行匹配(Regex)
#匹配最末两位为数字 $x=New-Object regex ('\d{2}','RightToLeft') #$x.RightToLeft $x.Match('abcd22') 结果:
- 暂停和恢复Activity Android
暂停和恢复Activity(Pausing and Resuming an Activity) 在正常的应用程序使用,前台activity有时会被其他可视化组件遮挡,从而 造成activity的暂停. ...
- Keeplived 配制图解
http://blog.csdn.net/tantexian/article/details/50056229
- JS加解密URL参数encodeURIComponent() decodeURIComponent()
参考1:http://www.w3school.com.cn/js/jsref_encodeURIComponent.asp 参考2:http://www.w3school.com.cn/js/jsr ...
- 三大文本处理工具grep、sed及awk的简单介绍
grep.sed和awk都是文本处理工具,虽然都是文本处理工具单却都有各自的优缺点,一种文本处理命令是不能被另一个完全替换的,否则也不会出现三个文本处理命令了.只不过,相比较而言,sed和awk功能更 ...
- debian7编译内核
第一个步骤“配置内核”. 在这里,我比较建议在发行版默认的config的基础上再进行配置,这样 配置出的内核和发行版本身才会有更好的相容性.比如可以在运行“make menuconfig”之前执行命令 ...
- scala Option 里的 orNull orElse getOrElse 区别和使用
Scala Option Scala Option类型用来表示一个值是可选的(有值或无值) Option[T] 是一个类型为 T 的可选值的容器: 如果值存在, Option[T] 就是一个 Some ...
- Divisibility
Description Consider an arbitrary sequence of integers. One can place + or - operators between integ ...
- css3 一些属性
==text-shadow== 语法:text-shadow: x-offset y-offset blur-radius color text-shadow:X 轴偏移量 Y轴偏移量 模糊半径 阴影 ...
- rpmdb: BDB0113 错误
解决方法: rpm --rebuilddb yum clean all