When adding a DockablePanel to the DockingManager, you add an object containing the method's address to the DockablePanels instance. The relevant code for this is. (Please don't code this because you will add the full code we need a bit later. This is only for explanatatory purpose.)
internal void AddPanel(DockablePanel dockPanel) {
AllDockPanels.Add(key, dockPanel);
dockPanel.ShowDockControls +=
new ShowDockControlsEventDelegate(dockPanel_ShowDockControls);
}
[ExhangingDataByDelegate3.JPG]
Figure 15: One of the DockablePanels (In this case, P1) throws a ShowDockControls event.
So this is how it will work and now lets code it.
On Top of your DockablePanel.cs, you now can add the delegates definition and you also can define the DockControlActivities Event. The top of DockablePanel.cs should now look like the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DockingBasicControls;
using DockingControls.WinAPI;
using DockingControls.Classes;
namespace DockingControls.Forms {
#region Enumerations & Delegatedeclarations
public enum BorderStyle { Fixed2D, Fixed3D,
Sizeable2D, Sizeable3D };
public enum BorderRange { None, Left, Right, Top, Bottom,
LeftTopCorner, LeftBottCorner,
RightBottCorner, RightTopCorner };
internal delegate void
DockedFormClosingEventDelegate(string key);
internal delegate void
ShowDockControlsEventDelegate(ShowControlEventArgs e);
#endregion
internal sealed partial class DockablePanel : UserControl
{
#region events
internal event DockedFormClosingEventDelegate
PanelClosing;
internal event ShowDockControlsEventDelegate
ShowDockControls;
#endregion
// ....
To fire the above event, you need to add the following method to the DockablePanels Methods. This is the standard method to get the event called only if a delegate is attached.
private void OnShowDockControls(ShowControlEventArgs ds) {
if (this.ShowDockControls != null) {
this.ShowDockControls(ds);
}
}
Next, you need to add a delegate for this event in the DockingManager. To do this, you add the delegate at the same time you add the DockablePanel.
internal void AddPanel(DockablePanel dockPanel) {
string key = "P" + _count.ToString();
// each DockablePanel gets a new number
// independing of some are maybe closed again.
// we start with "P0" p for panel
_count++;
dockPanel.Key = key;
AllDockPanels.Add(key, dockPanel);
// !!! we add the new delegate just here !!!
dockPanel.ShowDockControls +=
new ShowDockControlsEventDelegate(dockPanel_ShowDockControls);
dockPanel.PanelClosing +=
new DockedFormClosingEventDelegate(dockPanel_PanelClosing);
// now we attach the carrier to the DockablePanel;
AttachCarrier(dockPanel);
}
And in the created delegate, you set:
#region Delegates (DockingManager)
//. . .
private void dockPanel_ShowDockControls(ShowControlEventArgs e) {
ShowSinglePanelDockingControls(e);
}
#endregion
To calculate the positions of the buttons, you first inform the admin class which Buttons are used; then you calculate the positions of the buttons and the size the transparentForm, and last, you show the buttons. Additionally, you store the size of the InnerClientScreenWindow in the Dockingmanager This looks quite simple at this stage. Add the following:
#region Private Methods (DockingManager)
private void ShowSinglePanelDockingControls(ShowControlEventArgs e) {
_admin.SetStandardButtonSize();
_admin.CalculateDockingButtonPositions(e);
_innerScreenClientRectangle = _admin.InnerClientScreenRectangle;
_actDockFormSize = _admin.ActDockPanelSize;
ShowDockingButtons();
}
As you see, all the potential problems are moved to the DockAdministration class where you will calculate all this information. Now, let me explain what the InnerClientScreenWindow is.
First, take a look at setting all the StandardButtons size values in the DockAdministration class, because you need these values for the following calculations. The Standard Buttons are those that you need to use for BaseDocking. In the DockAdministration class, you have to add some fields, so that you are able to store needed values and calculation results.
internal class DockAdministration {
#region Fields
// BaseDocking Buttons (when mouse is in a free space,
// not over a docked panel )
Size buttonSize = new Size(48, 48);
Size tabButtonSize = new Size(53, 59); // the Center Button
// the LeftSide or RightSideButton,
// when mouse is over a panel
Size horButtonSize = new Size(59, 45);
// the Upper or lower Button,
// when mouse is over a panel
Size vertButtonSize = new Size(53, 83);
//. . . the existing Fields followed by
private Control[] LeftButtonStrips;
private Control[] TopButtonStrips;
private Control[] RightButtonStrips;
private Control[] BottomButtonStrips;
// A constant for calculation of Buttonposition:
// Some pixels from Button to border
private const int buttonOffset = 6;
private Rectangle[] _buttonRanges;
private Rectangle _innerClientScreenRectangle =
new Rectangle();
To be able to use these rectangle arrays, you have to initialize them in the Constructor. You must add the initialisation here, expanding the existing code to simply initialise the ButtonRanges rectangle Array with empty rectangles. They are enumerated using the buttonType enum you already have declared in the 'Administrative Cycles' section.
#region Ctor
internal DockAdministration(DockingManager dockManager) {
_dockManager = dockManager;
_buttonRanges = new Rectangle[] {
new Rectangle(), new Rectangle(), new Rectangle(),
new Rectangle(), new Rectangle(), new Rectangle(),
new Rectangle(), new Rectangle(), new Rectangle()
};
}
#endregion
Setting the StandardButtonSize means setting the values for left, right, top, and bottomButton, but you set the values for the DockingButtons you will need for AdvancedDocking to Empty. This way, you are sure that the unneeded Buttons don't matter in the calculations because their Size values are zero.
internal void SetStandardButtonSize() {
_buttonRanges[(int)buttonType.Left].Size = buttonSize;
_buttonRanges[(int)buttonType.Right].Size = buttonSize;
_buttonRanges[(int)buttonType.Top].Size = buttonSize;
_buttonRanges[(int)buttonType.Bottom].Size = buttonSize;
_buttonRanges[(int)buttonType.Upper].Size = Size.Empty;
_buttonRanges[(int)buttonType.Lower].Size = Size.Empty;
_buttonRanges[(int)buttonType.LeftSide].Size = Size.Empty;
_buttonRanges[(int)buttonType.RightSide].Size = Size.Empty;
_buttonRanges[(int)buttonType.Center].Size = Size.Empty;
}
Next, you have to add the CalculateDockingButtonPositions() method. To do this Calculation, you first need to calculate the InnerClientScreenRectangale because you need this information to calculate the DockingButtonsPositions(). Now, let me explain what the InnerClientScreenRectangle is.
Comments
There are no comments yet. Be the first to comment!