在项目中新建一个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 右键增加关闭,除此之外全部关闭的功能的更多相关文章

  1. 如何让MFC程序关闭按钮失效,也无法右击任务栏关闭窗口来关闭?

    如何让MFC程序关闭按钮失效,也无法右击任务栏关闭窗口来关闭,即右键任务栏的关闭窗口失效呢?很简单,有一个小窍门就是:响应IDCANCEL消息,具体实现如下: 首先定义消息映射:ON_BN_CLICK ...

  2. win7/8 关闭非正常关机的自动修复功能

    win7/8 关闭非正常关机的自动修复功能 1.桌面右键新建一个文档文本,双击打开文件新建文本文档,复制以下命令到文本里面! bcdedit /set {default} bootstatuspoli ...

  3. 我为 Netty 贡献源码 | 且看 Netty 如何应对 TCP 连接的正常关闭,异常关闭,半关闭场景

    欢迎关注公众号:bin的技术小屋,本文图片加载不出来的话可查看公众号原文 本系列Netty源码解析文章基于 4.1.56.Final版本 写在前面..... 本文是笔者肉眼盯 Bug 系列的第三弹,前 ...

  4. 如何让Visual Studio 清除最近打开项目 关闭上次未关闭的标签窗口

    删除最近打开的文件: 打开HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\FileMRUList 删除最近打开的项目: 打开HKEY_CUR ...

  5. Sails 关闭自动路由 Automatic Routes 功能。

    Sails 关闭自动路由 Automatic Routes 功能. Sails 中的路由两种:Custom Routes 和 Automatic Routes,自定义路由和自动路由.详见文档: Sai ...

  6. ExtJs4.2中Tab选项卡的右击关闭其它和关闭当前功能不准确的解决方法

    一.ExtJs4.2中Tab选项卡的右击关闭其它和关闭当前功能不准确的解决方法 二.找到ux目录下的TabCloseMenu.js文件,将内容替换成下面代码. 三.代码: /** * Plugin f ...

  7. centos 关闭selinux 临时关闭selinux 报错 setenforce: setenforce() failed

    关闭selinux的方法有两种:临时关闭和永久关闭. 查看selinux的状态:estatus [root@--- ~]# sestatus SELinux status: enabled SELin ...

  8. win7或win2008系统中,出现【已停止工作,联机检查解决方案并关闭该程序,关闭程序】解决方法!

    win7或win2008系统中,出现[已停止工作,联机检查解决方案并关闭该程序,关闭程序]解决方法! 经过摸索,点击[控制面板]-[操作中心]-[更改操作中心设置]-[问题报告设置]-[从不检查解决方 ...

  9. Linux学习之设置联网,关闭防火墙,关闭selinux

    桥接模式,给一台物理机,有自己独立的IP. boot分区,引导分区,系统启动,内核文件. swap分区,内存扩展分区.1.5或2倍.内存不够的时候,会写入其中.正常给8G或者16G就够了.不需要非要1 ...

随机推荐

  1. Mr.Miss

    umbrella please here my ticket number five sorry sir cloakroom Madam Mr. Mrs Miss lady gentleman mal ...

  2. DashClock

    https://github.com/romannurik/dashclock/ https://github.com/nhaarman/DashPinkpop dashclock-master.zi ...

  3. Servlet---JavaWeb技术的核心基础,JavaWeb框架的基石(二)

    一.Servlet之Request         Web服务器会对收到的每一次客户端http请求分别创建一个用于代表请求的request对象和代表响应的response对象.要获取客户端提交的数据需 ...

  4. mysqlpump 原理

    Oracle官方多线程逻辑备份工具 昨天Inside君写到MySQL 5.7.11版本发布,其中最有意义的部分在于官方修复了之前mysqlpump工具一致性备份的问题,使得mysqlpump工具在生产 ...

  5. java_io_操作封装

    package com.wiker; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import j ...

  6. HTML 之 Embed兼容问题

    首先IE只支持对Object的解析,火狐.谷歌.Safari只支持对Embed的解析. 1.传统的方法 <object classid="clsid:d27cdb6e-ae6d-11c ...

  7. JavaScript 正则表达式相关理解

    1.使用正则的test.exec方法而且带有g属性进行连续匹配的时候, 如果每次匹配之前 lastIndex属性没有清零. <script> var str='123qweQWE125|2 ...

  8. Objective-C ,ios,iphone开发基础:多个视图(view)之间的切换2,使用导航栏控制,以及视图之间传值。

    首先需要说明的是每个应用程序都是一个window,背景色为黑色.在window上可以跑多个view进行来回切换,下面就通过手动写代码来体现导航栏切换view的原理. 第一步,新建一个single vi ...

  9. Url几个常用的函数

    parse_url() 本函数解析一个 URL 并返回一个关联数组,包含在 URL 中出现的各种组成部分. 本函数不是用来验证给定 URL 的合法性的,只是将其分解为下面列出的部分.不完整的 URL ...

  10. 转: Lua 语言 15 分钟快速入门

    看点: 1. 以很特殊的方式工,把Lua的语法全部输出一段,很容易让人记住..不错 转: http://blog.jobbole.com/70480/