Use of the WinForm interface layout control WeifenLuo. WinFormsUI. Docking & quot; (2) and winform paging Control

Source: Internet
Author: User

Use of the WinForm interface layout control WeifenLuo. WinFormsUI. Docking (2) and winform paging Control

Use of the WinForm interface layout control WeifenLuo. WinFormsUI. Docking

(2)

Prepared by: CC Dad

 

 

Today, I want to continue sharing this great widget with you. If you are interested, you can discuss and learn it together. Otherwise, you can skip it.

 

1. Improvements to DockPanel:

Some technical articles on the Internet show that some areas can be further improved. For example, when you double-click a Tab, the current Tab is directly represented by this form, it is separated from the frame of the main form to form a floating form. This is not what we want. Some people modify the source code and double-click it to close it. (Test OK)

 

The following link shows the source of the official shared code. You can use svn to download the latest code. All the modifications are based on the source code.

Http://sourceforge.net/projects/dockpanelsuite

 

Double-click to close the tag code. Modify the protected override void WndProc (ref Message m) function code in the DockPaneStripBase. cs class as follows:

 

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, add the ContextMenuStrip menu tool in the tool and close all to close all the other three menus (I copied them from other online users and did not perform a test)

/// <Summary>
/// Many forms have a right-click menu in the Tab, and the right-click menu is closed, so it is best to inherit DockContent,
/// Let other forms have this right-click menu as long as they inherit this
/// </Summary>
Public class DockContentEx: DockContent
{
// Right-click the tag to display the close menu
Public DockContentEx ()
{
System. Windows. Forms. ContextMenuStrip cms = new System. Windows. Forms. ContextMenuStrip ();
//
// TsmiClose
//
System. Windows. Forms. ToolStripMenuItem tsmiClose = new System. Windows. Forms. ToolStripMenuItem ();
TsmiClose. Name = "cms ";
TsmiClose. Size = new System. Drawing. Size (98, 22 );
TsmiClose. Text = "disabled ";
TsmiClose. Click + = new System. EventHandler (this. tsmiClose_Click );
//
// TsmiALLClose
//
System. Windows. Forms. ToolStripMenuItem tsmiALLClose = new System. Windows. Forms. ToolStripMenuItem ();
TsmiALLClose. Name = "cms ";
TsmiALLClose. Size = new System. Drawing. Size (98, 22 );
TsmiALLClose. Text = "close all ";
TsmiALLClose. Click + = new System. EventHandler (this. tsmiALLClose_Click );
//
// TsmiApartFromClose
//
System. Windows. Forms. ToolStripMenuItem tsmiApartFromClose = new System. Windows. Forms. ToolStripMenuItem ();
TsmiApartFromClose. Name = "cms ";
TsmiApartFromClose. Size = new System. Drawing. Size (98, 22 );
TsmiApartFromClose. Text = "close all other items ";
TsmiApartFromClose. Click + = new System. EventHandler (this. tsmiApartFromClose_Click );
//
// TsmiClose
//
Cms. Items. AddRange (new System. Windows. Forms. ToolStripItem [] {
TsmiClose, tsmiApartFromClose, tsmiALLClose });
Cms. Name = "tsmiClose ";
Cms. Size = new System. Drawing. Size (99, 26 );
This. TabPageContextMenuStrip = cms;
}
Private void tsmiClose_Click (object sender, EventArgs e)
{
This. Close ();
}
Private void tsmiALLClose_Click (object sender, EventArgs e)
{
DockContentCollection contents = DockPanel. Contents;
Int num = 0;
While (num <contents. Count)
{
If (contents [num]. DockHandler. DockState = DockState. Document)
{
Contents [num]. DockHandler. Hide ();
}
Else
{
Num ++;
}
}
}
Private void tsmiApartFromClose_Click (object sender, EventArgs e)
{
DockContentCollection contents = DockPanel. Contents;
Int num = 0;
While (num <contents. Count)
{
If (contents [num]. DockHandler. DockState = DockState. Document & DockPanel. ActiveContent! = Contents [num])
{
Contents [num]. DockHandler. Hide ();
}
Else
{
Num ++;
}
}
}

}

The following are some technical documents about the control for your reference.

Http://www.cnblogs.com/luomingui/archive/2013/09/19/3329763.html

Http://blog.csdn.net/dqvega/article/details/7594923

 

The modified dll is as follows:

Http://download.csdn.net/detail/shilei07068124/4506742

 

Join the technology sharing Group

 

Related Article

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.