Introduction

Some days ago as I coded the HelloWorld in C#, there was darkness around me. After crawling through all the articles from CodeProject, there was light. A few days later I got my first version of magic library, from this time my HelloWorld applications looks cool.

Now, much time later, spent millions of hours coding C# in my spare time and on my job, I still use the magic library. With the knowledge gained from using commercial products like Syncfusion Essentiel Tools I felt it's time to write a component for Visual Studio which provides easy access to the great docking features of Magic Library.

Key features

You control the docking behavior of your controls in the properties (PropertyGrid).

Automatic State Persistence takes care of user customization. The customized layouts are stored in the Isolated Storage.

Accessible wrapped DockingManager, all features of future releases of DockingManager are reachable.

Background

The component implements the IExtenderProvider interface and wraps a Crownwood.Magic.Docking.DockingManager. The IExtenderProvider extends the controls on your Form with a few of the Crownwood.Magic.Docking.Content properties. At run time the component manages the Content settings for each control and attaches the controls to the wrapped DockingManager.

Using the code

Before you begin, make sure your project has a valid reference to the Magic Library. Go to the Toolbox window, right-click and select Customize Toolbox from the context menu. In the Customize Toolbox dialog, go to the .NET Framework Components tab and select the DockingManagerExtender.dll assembly that you just compiled. Now drop the DockingManagerExtender component to your form.

The component provides the following:

Public Instance Properties

AutomaticStatePersistence

Enable or disable the Automatic State Persistence feature. If enabled, the customized docking settings made by the user are persistent by User/Domain/WorkingArea

ContainerControl

Gets or sets the object to which the docking manager instance is attached

DockingManager

The wrapped Crownwood.Magic.Docking.DockingManager. Direct access to all properties.

InnerControl

Sets or gets the Control for which the docking windows will not be allowed to dock inside of the specified control.

OuterControl

Sets or gets the Control for which docking windows will not be allowed to dock outside of the specified control.

PlainTabBorder

Gets or sets the flag indicating that the appearance is defined as VisualStyle.Plain and this PlainTabBorder property is defined then a full dumped border is drawn around the docking window content.

After enabling docking for your controls, hit F5 to start debugging. If everything went right the controls are docked, finish.

In depth

There are three classes which where used to build this component. For detailed view, please refer to the NDOC generated Help File.

Classes

Class

Description

DockingContent

Wraps Crownwood.Magic.Docking.Content and extends it with needed properties.

DockingManagerConverter

DockingManagerConverter provides a TypeConverter for the Crownwood.Magic.Docking.DockingManager

DockingManagerExtender

DockingManagerExtender enhances Crownwood.Magic.Docking.DockingManager for design time. It extends the controls on your form with properties, which defines the docking behavior at run time.

Conclusion

The order of the controls in the InitializeComponent() method is important for docking order. If you like to dock two controls (A,B) in tabbed mode on the left side, and another (C) not tabbed on the left upper side, please make sure control (C) comes before (A,B), otherwise the docking order is not correct.

Every time you change the docking properties with AutomaticStatePersistence, true, you do not see the changes made directly. The DockingManager overrides the changes made with the stored settings. To solve this problem you should not use AutomaticStatePersistence for development.

You like to dock a panel from the startup of your application? That's what the docking extender is all about. Just follow the article above and the panel is docked at startup, otherwise you found a bug in the code, let me know.

I have a Panel which is Dock enabled to left at design time...When the application starts up , i resize the panel to say SetContentSize(300,600) ..
But the panel will be visible AND SPANNING OVER THE REST OF THE CONTROLS in the form thus making the other controls invisible. !!!

there will be a NUT like icon on the dockable panel which is clicked to make the panel docked..right? thats how dockable windows used to behave
But i want to capture the event when the user clicks the NUT ICON on top right of the dockable window and use it to make the panel DOCKED TO LEFT when the app starts up..

I have tried your demo of SampleDocking provided by you. I found it interested. I understand it and found that you have done a great job. I have tried for all events and content windows. But the problem is I want to provide my own event handler for close button and hide button. I want to have my own handler for close button. so pls give me a solution. I want to track the event whether close button and hide button clicked or not clicked.

I have used th emagic controls before,but stopped because of the difficulty in getting everythign to work properly. I have written a few extenders and decided to come back to the magic controls. Your implementation saved me a lot of time!

When pressed the autohide button in a docked window the window is minimized when you hover the mouse over the tab of the window it then shows the window. What i would like is to control this functionality programatically. How do i do this ?

I suggest you use Sandbar from divelements, a personal edition is available.

about the licenses (SandDock from divelements)

SandDock can be downloaded for use with free software free of charge. The license requires your software generate no profit, be available for public download over the internet and contain a link to this website.

This license does not permit distribution of the product with any commercial application or application that is not available for free download.

for most parts, magic library works just as I expect, but after a while, I have a problem.

I create an instance of Content and add it to _dockingManager, the content of the Content instance comes from another Windows Form, where I have put several controls on it. when the app runs, part of a control goes beyond the border of the dock window, after I manually resize the window, it then fit well. I have tried to use SetWindowsPos API to do the same thing but failed to achieve the same result. the Demo here seems have the same problem. does anybody have encountered the same problems? thanks