Weifenluo. winformsui. Docking -- a little improvement on dockpanel

Source: Internet
Author: User

From: http://www.cnblogs.com/yvesliao/archive/2008/08/26/1276609.html

1. When you double-click a tab, the current tab is directly separated from the frame of the main form to form a floating form. This is not what I want. I changed it to double-click to close it.
In the wndproc method of dockpanestripbase. CS, the left-click message is re-processed (the comment below is the original method, and the line below is changed ):

[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; // indicates that the window is restored to the initial size and is detached from any dock.
If (content. dockhandler. hideonclose)
Content. dockhandler. Hide (); // hide
Else
Content. dockhandler. Close (); // close

}

 

Return;
}

Base. wndproc (ref m );
Return;
}

2. Many forms have a right-click menu in the tab, and the right-click menu is closed, so it is best to inherit dockcontent so that other forms have this right-click menu as long as they inherit it.

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
{
// Right-click the tag to display the close menu
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 = "disabled ";
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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.