(转) 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 ...
随机推荐
- Java中的Annotation(2)----Annotation工作原理
Java中的Annotation(2)----Annotation工作原理 分类: 编程语言2013-03-18 01:06 3280人阅读 评论(6) 收藏 举报 上一篇文章已经介绍了如何使用JDK ...
- C++ 不支持模版的分离式编译
1.C++不支持模版的分离式编译,为什么? C++是分别,单独编译,对于每个cpp文件,预编译为编译单元,这个编译单元是自包含文件,编译的时候,不需要其他的文件,编译好了,生成obj文件,然后连接成e ...
- INNOBACKUPEX热备MYSQL数据
http://www.databaseclub.com/2014/11/innobackupex/ 1)对MySQL进行全备份1.备份数据 1 innobackupex --user=userna ...
- HelloSpark.scala
/** * Created by root on 9/6/15. */ import org.apache.spark.SparkContext import org.apache.spark.Spa ...
- #pragma_pack(n)_与___attribute(aligned(n))
#pragma pack(n) 与 __attribute(aligned(n)) 在C语言中,结构是一种复合数据类型,其构成元素既可以是基本数据类型(如int.long.float等)的变量,也 ...
- Android基本控件之ListView(一)
我们在使用手机的时候,通常看到,像通讯录,QQ列表样式的东西,这里来解释一下,其实那些都是一个ListView 今天,我们就来详细的讲解一下ListView这个控件 ListView中每条显示的数据都 ...
- jsp自定义标签分页
第一步:建立分页实体page类 package com.soda.util; /** * @description 分页实体类 * @author line * @time 2016年8月28日11: ...
- jq选择器 第一部分
没有什么新意,全是从网上摘抄的,如果哪天忘了,就来查查吧. 1. id选择器(指定id元素) 将id="one"的元素背景色设置为黑色.(id选择器返单个元素) $(documen ...
- React Redux Sever Rendering实战
# React Redux Sever Rendering(Isomorphic JavaScript) ![React Redux Sever Rendering(Isomorphic)入门](ht ...
- vs2010 调试C++程序 快捷键
命令名 快捷键 说明 调试.应用代码更改 Alt + F10 启动生成操作,利用它可以通过“编辑并继续”功能应用对正在调试的代码所作的更改. 调试.自动窗口 Ctrl + D,Ctrl + A 显示“ ...