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.