(转) 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 ...
随机推荐
- android 手电筒的实现
android手机用闪光灯做成手电筒的应用非常多,可是有的不能用. 后来发现是除了把 camera device的 flashmode设置成torch外还要打开预览: 以下是代码: MainActiv ...
- MVC4 EF6 MYSQL
在MVC的框架下连接mysql数据库 将EF框架升级到EF6 将NEW JSON升级到与之相匹配的版本 然后进行相应的配置就可以了
- QT5 串口收发实例代码
以下代码是自己测试门禁系统使用的 主要用到了串口的接收和发送 开发环境:xp QT5.1.1 串口:38400 N 8 1 自动检测可用串口 在xp上测试没问题 有些usb转串口会出现波特 ...
- 常见AutoCAD病毒(acad.fas、acad.lsp)清除方法
常见AutoCAD病毒(acad.fas.acad.lsp)清除方法 acad.fas.acad.lsp这两种病毒是最常见的CAD病毒了,而且往往同一时候出现.因为其本身对系统并不具备危害性,不过恶作 ...
- Python学习 之 运算符&表达式
1.Python运算符包括:赋值运算符.算术运算符.关系运算符.逻辑运算符. 表达式是将不同的数据(包括变量.函数)用运算符号按一定规则连接起来的一种式子. 2.赋值运算符:=.+=.-=.*=./= ...
- Lua调用自定义C++类
弄了一天终于会Lua调用自定义C++类.不容易啊. 我的电脑是64位的,装了64的Python不行,装了32位的就可以了,靠!下面是报错信息 python pyyaml Cheetah全都是装32位的 ...
- win7 下 qwt安装教程
一.安装:qwt的安装很简单,可以参看它的install文档.1.解开下载下来的zip文件,比如解开到d:\qt\qwt-5.0.2目录下,修改目录下的qwtconfig.pri文件里面的安装路径,比 ...
- 给jdk写注释系列之jdk1.6容器(11)-Queue之ArrayDeque源码解析
前面讲了Stack是一种先进后出的数据结构:栈,那么对应的Queue是一种先进先出(First In First Out)的数据结构:队列. 对比一下Stack,Queue是一种先进先出的容 ...
- 关于TreeSet倒序排列和自定义排列
本文部分转自:http://blog.csdn.net/kaituozhe345/article/details/6842945 1.TreeSet的自然排序. TreeSet存储对象的时候, 可以排 ...
- Hibernate常见面试题
1.什么是Hibernate的并发机制?怎么去处理并发问题? Hibernate并发机制: a.Hibernate的Session对象是非线程安全的,对于单个请求,单个会话,单个的工作单元(即单个事务 ...