The use of the layout control "WeifenLuo.WinFormsUI.Docking" for WinForm Interface development

Source: Internet
Author: User

Http://www.cnblogs.com/wuhuacong/archive/2009/07/09/1520082.html

This article describes the design of the layout interface in the development of the WinForm program, and describes how to use the layout control "WeifenLuo.WinFormsUI.Docking" in my shared software.

Layout control "WeifenLuo.WinFormsUI.Docking" is a great open source control that has been used by people who have experienced it, the control is powerful, beautiful, and no less than commercial controls. And the control is also relatively simple to use. First look at the program interface that the control uses to display the effect.

The interface of the distribution network visualization management system:

Shen Tian Star Water Delivery Management System network version of the interface:

I use this layout control in several shareware, we first take the "Deep Field star Water management System Network version" of the software as an example, how to complete the design and display of the interface.

1, first, we add a main interface form named MainForm, the form IsMdiContainer is set to true, that is, the format of the multi-document form. Drag the layout control "WeifenLuo.WinFormsUI.Docking.DockPanel" into the main form mainform, and set several properties:

The dock is fill, Documentstyle is Dockingmdi, and RightToLeftLayout is true.

The meaning of these properties should not be difficult, the dock is the area covering the entire MDI form, Documentstyle is a multi-document type, righttoleftlayout means that the newly opened window is docked in the right area.

Let's look at the design interface view as shown below.

2, the main interface is basically OK, in addition we see the "Water Management System Network version" of the interface has a left-hand toolbar, it is actually in a docked form, we added a form to host the relevant tool shortcut button display. A form named Maintoolwindow, inherited from WeifenLuo.WinFormsUI.Docking.DockContent.

Where the "Hideonclose" attribute is important, this property is generally set to true, which means that when you close the window, the form is only hidden and not really closed.

The left window Maintoolwindow implementation of the docked code is loaded in the MainForm constructor or load function.

Maintoolwin.show (This.dockpanel, dockstate.dockleft);

3, for the tool window we have finished, but the main business window has not been done, that is, the following part of the content.

For convenience, we define a base class form, named BaseForm, that inherits from Dockcontent, as shown below

public class Baseform:dockcontent

Then each business window inherits BaseForm.

4, the remaining content is how to display the relevant business window in the main form mainform, the code shown below

public partial class Mainform:form
{
#region Property Fields

Private Maintoolwindow Maintoolwin = new Maintoolwindow ();
Private Frmproduct frmproduct = new Frmproduct ();
Private Frmcustomer Frmcustomer = new Frmcustomer ();
Private Frmorder Frmorder = new Frmorder ();
Private Frmstock Frmstock = new Frmstock ();
Private Frmcomingcall Frmcomingcall = new Frmcomingcall ();
Private frmdeliving frmdeliving = new frmdeliving ();
Private Frmtickethistory frmhistory = new Frmtickethistory ();

#endregion

Public MainForm ()
{
InitializeComponent ();

SplashScreen.Splasher.Status = "The relevant content is being displayed";
System.Threading.Thread.Sleep (100);

Maintoolwin.show (This.dockpanel, dockstate.dockleft);
Frmcomingcall.show (This.dockpanel);
Frmdeliving.show (This.dockpanel);
Frmhistory.show (This.dockpanel);
Frmstock.show (This.dockpanel);
Frmproduct.show (This.dockpanel);
Frmcustomer.show (This.dockpanel);
Frmorder.show (This.dockpanel);

SplashScreen.Splasher.Status = "initialization complete";
System.Threading.Thread.Sleep (50);

SplashScreen.Splasher.Close ();
}

5. Basic Action Event function for basic window posted below

private void Menu_window_closeall_click (object sender, EventArgs e)
{
Closealldocuments ();
}

private void Menu_window_closeother_click (object sender, EventArgs e)
{
if (Dockpanel.documentstyle = = Documentstyle.systemmdi)
{
Form activemdi = Activemdichild;
foreach (Form form in Mdichildren)
{
if (form! = Activemdi)
{
Form. Close ();
}
}
}
Else
{
foreach (Idockcontent document in Dockpanel.documentstoarray ())
{
if (!document. dockhandler.isactivated)
{
Document. Dockhandler.close ();
}
}
}
}

Private Dockcontent finddocument (string text)
{
if (Dockpanel.documentstyle = = Documentstyle.systemmdi)
{
foreach (Form form in Mdichildren)
{
if (form. Text = = text)
{
return form as dockcontent;
}
}

return null;
}
Else
{
foreach (dockcontent content in dockpanel.documents)
{
if (content. Dockhandler.tabtext = = text)
{
return content;
}
}

return null;
}
}

Public Dockcontent showcontent (string caption, Type formtype)
{
Dockcontent frm = finddocument (caption);
if (frm = = null)
{
frm = Childwinmanagement.loadmdiform (Portal.gc.MainDialog, FormType) as dockcontent;
}

frm. Show (This.dockpanel);
frm. BringToFront ();
return frm;
}

public void Closealldocuments ()
{
if (Dockpanel.documentstyle = = Documentstyle.systemmdi)
{
foreach (Form form in Mdichildren)
{
Form. Close ();
}
}
Else
{
idockcontent[] documents = Dockpanel.documentstoarray ();
foreach (Idockcontent content in documents)
{
Content. Dockhandler.close ();
}
}
}

Finally presented the control file, you can come down to play.

Http://files.cnblogs.com/wuhuacong/WeifenLuo.WinFormsUI.Docking.rar

The use of the layout control "WeifenLuo.WinFormsUI.Docking" for WinForm Interface development

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.