How to Use the dotnetbar control to construct a multi-Document Interface

Source: Internet
Author: User

Some time ago, I wrote an article titled using excellent. NET interface control to create a trendy interface effect "describes the interface effect of Dotnetbar. Although many disputes have been raised about the control effect, the use of this control is also a solution to the interface. This article continues to explore the use of this control, the use of this control in QQ soutong Enterprise Edition Software has made a complete transformation, this article describes how to use the Dotnetbar control to implement the multi-document interface. First, let's take a look at the main interface of the software, as shown in.

 

This interface mainly uses the Bar control to implement the interface effects of multiple documents. Each sub-form is a user control. Of course, it also includes the CtrlMdiBar class for containers containing various forms. It is also a user control, place the container in the RibbonClientPanel area of the Ribbon control on the main interface, and then dynamically create or activate a form page each time the form is opened. This achieves the multi-Document Interface effect.

Bar = new CtrlMdiBar ();
Bar. DockTabClosed = new DockTabClosedDelegate (OnDockItemClosed );
SetDetailPanel (bar );

 

Private CtrlMdiBar bar;
Private Dictionary <string, DockContainerItem> MdiDict = new Dictionary <string, DockContainerItem> ();

Public void SetDetailPanel (UserControl uc)
{
If (uc = null)
{
Throw new ArgumentNullException ("uc", @ "User Control uc cannot be blank ");
}

Uc. Dock = DockStyle. Fill;
RibbonDetailPanel. Controls. Clear ();
RibbonDetailPanel. Controls. Add (uc );
}

Public void SetMdiForm (UserControl uc, string itemText)
{
DockContainerItem = null;
String type = itemText; // uc. GetType (). Name;
If (MdiDict. ContainsKey (type ))
{
Item = MdiDict [type];
}
Else
{
PanelDockContainer panel = new PanelDockContainer ();
Item = new DockContainerItem ();
Item. Control = panel;
Item. Text = itemText;
Uc. Dock = DockStyle. Fill;
Panel. Controls. Add (uc );

MdiDict. Add (type, item );
Bar. bar1.Items. Add (item );
}
Bar. bar1.SelectedDockContainerItem = item;
This. Refresh ();
}

Private void OnDockItemClosed (DockContainerItem)
{
String type = item. Text;
If (MdiDict. ContainsKey (type ))
{
MdiDict. Remove (type );
}
}

 

 

Each time a button opens a form page, you only need to call the function, as shown in the following steps to open the form page.

Private void btnMyQunUser_Click (object sender, EventArgs e)

{
SetMdiForm (new CtrlGroupUser (), MDIForm. query the personal group member. ToString ());
}

Private void btnMyQQUser_Click (object sender, EventArgs e)
{
SetMdiForm (new CtrlQQContact (), MDIForm. Query personal QQ friends. ToString ());
}

Private void btnXiaoyou_Click (object sender, EventArgs e)
{
SetMdiForm (new CtrlXiaoyou (), MDIForm. query QQ alumni. ToString ());
}

 

 

The CtrlMDIBar container is a user control that places a Bar control of Dotnetbar and calls the delegate to process the events of the control. The main code is as follows.

Public delegate void DockTabClosedDelegate (DockContainerItem item );
Public partial class CtrlMdiBar: UserControl
{
Public DockTabClosedDelegate DockTabClosed;

Public CtrlMdiBar ()
{
InitializeComponent ();
}

Private void bar1_DockTabClosed (object sender, DevComponents. DotNetBar. DockTabClosingEventArgs e)
{
// MessageExUtil. ShowTips ("DockTabClosed ");
If (DockTabClosed! = Null)
{
DockTabClosed (e. DockContainerItem );
}
}

...............

 

 

 

In this way, to add a form page to the container, you only need to define another user control and design the interface and other processing methods, it is very easy to add an interface form page dynamically.

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.