Click here to Skip to main content
Click here to Skip to main content

Visual Studio IDE like Dock Container - Second Version

By , 2 Oct 2009
 

Introduction

This is the second version of the product Crom.Controls.Docking.

What's new

The following functionalities were added/changed:

  • Complex docking: it is now possible to create complex layouts:

    Docking001_600x432.PNG

  • Preview on mouse hover over auto-hidden buttons:

    Docking002_600x432.PNG

  • Form selector using Ctrl+Tab:

    Docking003_600x432.PNG

  • Save/load layout

Using the Code

Here are the basic steps that you need to do for using the control:

  • Add reference to Crom.Controls.dll assembly in your project
  • Place a DockContainer control on your form and set its Dock property to DockStyle.Fill
After completing these steps you can start using the control.

Adding a form to the dock guider container

First you need to add a form to guider using the method:
    DockableFormInfo Add(Form form, zAllowedDock allowedDock, Guid formIdentifier)

The parameters are:

  • form which should be a not null, not disposed instance of the form to guide, with the following properties set:
    • FormBorderStyle = FormBorderStyle.SizableToolWindow
    • TopLevel = false
  • allowedDock is the enumeration of the places where the form is allowed to be docked.
  • formIdentifier is an unique identifier associated with the form. These identifiers will be used when the layout state is saved/restored so they should be defined as constants in your application.
When adding a form to the guider, you'll receive a DockableFormInfo object. This object contains information about the guided form and is required by DockContainer on any operation with the form.

Docking a form added to the container

You can dock a form previously added to the container by calling one of the methods:
  • void DockForm(DockableFormInfo info, DockStyle dock, zDockMode mode)
  • void DockForm(DockableFormInfo info, DockableFormInfo infoOver, DockStyle dock, zDockMode mode)
The first method should be called when docking the form directly in the container, the second should be called when docking the form over an existing form. The parameters are:
  • info which should be a not null, not disposed instance of the form information obtained after adding a form to guider.
  • dock initial dock of the form (must be a valid dock value, other than DockStyle.None)
  • mode initial dock mode with one of the values:
    • zDockMode.Outer to dock the form on one of the margin edges of the container.
    • zDockMode.Inner to dock the form near the center of the free area of the container.
  • infoOver is the information of the form over which you want to dock your form.

Undocking a docked form

You can undock a docked form by calling the method:
    void Undock(DockableFormInfo info, Rectangle hintBounds)
The parameters are:
  • info which should be a not null, not disposed instance of the form information obtained after adding a form to guider.
  • hintBounds are the proposed bound of the form after will be undocked.

Removing a from from container

You can remove the from from container by calling the method:
    void Remove(DockableFormInfo info)
where info is the not null, not disposed instance of the form information obtained after adding the form to guider.

Getting the forms added in the container

You can get the count of forms added in the container by calling the property:
    int Count
    {
      get;
    }
You can get the information for a form added in the container by calling the property:
    DockableFormInfo GetFormInfoAt(int index)
where the index is the form index with valid values from 0 (zero) to Count - 1

Toggling the AutoHide mode of a docked window

To toggle the AutoHide mode of a docked window you should call the method:
    void SetAutoHide(DockableFormInfo info, bool autoHide)
The parameters are:
  • info which should be a not null, not disposed instance of the docked form information obtained after adding a form to guider.
  • autoHide is the flag indicating if should set auto-hide mode(true) or unset it(false)

Selecting a form

To select the input for a form you should set (true) the IsSelected property of DockableFormInfo object associated with the form. To intercept when a form is selected/deselected, you should connect to the SelectedChanged event of DockableFormInfo object associated with the form.

Associating context menu

To associate a context menu to a guided form you should connect to the ShowContextMenu event of the DockContainer control. The handler of this event should be something like:
     void OnDockerShowContextMenu(object sender, FormContextMenuEventArgs e)
     {
        contextMenuStrip1.Show(e.Form, e.MenuLocation);
     }

Preventing the close of a form

To disable closing a form you should connect to FormClosing event of the DockContainer control. The handler of this event should be something like:
     void OnDockerFormClosing(object sender, DockableFormClosingEventArgs e)
     {
        DockableFormInfo info = _docker.GetFormInfo(e.Form);
        if (info.Id == new Guid("0a3f4468-080b-404e-b012-997b93ed2005"))
        {
           e.Cancel = true;
        }
     }

Destroying a closed form

To destroy a closed form you shoud connect to FormClosed event of the DockContainer control. The handler of this event should be something like:
     void OnDockerFormClosed(object sender, FormEventArgs e)
     {
        e.Form.Close();
     }

Saving/restoring the container layout

To save/restore the container layout you need to use an object of type DockStateSerializer. To save the container layout you should call from DockStateSerializer the method:
    void Save() 
The layout state is saved by default in the local application data folder of your application. This default path is given by the serializer.SavePath property of the serializer and can be changed through this member. To load the container layout you should call from DockStateSerializer the method:
    void Load(bool clear, FormFactoryHandler formsFactory)
The parameters are:
  • clear a flag indicating if shoul clear all existing forms from the docker, before restoring the state (recommended value is true).
  • formsFactory is a handler to a form factory method.
The form factory method signature is Form CreateTestForm(Guid identifier). This method should return the instance of the form associated with given Guid identifier.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Cristinel Mazarine
Romania Romania
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNice Controlmemberghvnd28 Jul '11 - 10:08 
Hi,
 
you made a very nice control.
The only thing that's sucking is, that I have to pass the class GUID's for each form.
You could make thing's much simpler with an integer field that works like a primary key with increment in a database.
To pass/generate this long confusing string is really disgusting.
Or you can use a hashtables or even a dictionaries with a primarykey to indentify the different forms.
 

Greets
simon
GeneralMy vote of 2memberkribo5 May '11 - 14:41 
nice little control
Generalwhy your codes never workmembervincezed16 Apr '11 - 12:35 
your codes never works.. version one shows the same errors as version two...
 
can u resolve it...
 
it shows exe not found...
GeneralDocked Window not on topmemberDeepesh Dhapola28 Mar '11 - 18:23 
Hi,
 
I liked this control library hence started using it. I noticed a small issue wherein docked window goes behind any other controls dropped on the dockcontainer. any idea if I need to set any properties to fix this?
 
thanks,
Deepesh
GeneralMy vote of 3memberTheingi Win10 Feb '11 - 13:20 
Good Article for Docking
 
Thanks! Theingi
GeneralMy vote of 5memberv# guy27 Jan '11 - 11:51 
Great for me
QuestionHow to move dockable window outside container (client area)memberharoldsy8 Dec '10 - 13:54 
How to move dockable window outside container (client area)
thanks
 
Harold
GeneralBug - SavingmemberMember 476655714 Nov '10 - 7:35 
If there are three forms in a row its switching the dock in one of them when saving
 
Example: look at the dock in the second form
 
code:
DockContainer1.DockForm(DockInfo_Folders, DockStyle.Right, Crom.Controls.Docking.zDockMode.None)
DockContainer1.DockForm(DockInfo_Courses, DockInfo_Folders, DockStyle.Bottom, Crom.Controls.Docking.zDockMode.Outer)
DockContainer1.DockForm(DockInfo_Categories, DockInfo_Courses, DockStyle.Bottom, Crom.Controls.Docking.zDockMode.Outer)
 
This is what it saved:
 
<Form>
      <Guid>00000000-0000-0000-0000-000000000002</Guid>
      <AllowedDock>All</AllowedDock>
      <CurrentDock>Right</CurrentDock>
      <CurrentMode>None</CurrentMode>
      <IsSelected>false</IsSelected>
      <IsAutoHide>false</IsAutoHide>
      <Width>268</Width>
      <Height>193</Height>
   </Form>
   <Form>
      <Guid>00000000-0000-0000-0000-000000000005</Guid>
      <AllowedDock>All</AllowedDock>
      <CurrentDock>Top (Suppose to be Bottom)</CurrentDock>
      <CurrentMode>None</CurrentMode>
      <IsSelected>false</IsSelected>
      <IsAutoHide>false</IsAutoHide>
      <Width>268</Width>
      <Height>236</Height>
      <ParentGuid>00000000-0000-0000-0000-000000000002</ParentGuid>
   </Form>
   <Form>
      <Guid>00000000-0000-0000-0000-000000000001</Guid>
      <AllowedDock>All</AllowedDock>
      <ShowSettings>false</ShowSettings>
      <CurrentDock>Bottom</CurrentDock>
      <CurrentMode>None</CurrentMode>
      <IsSelected>false</IsSelected>
      <IsAutoHide>false</IsAutoHide>
      <Width>268</Width>
      <Height>226</Height>
      <ParentGuid>00000000-0000-0000-0000-000000000005</ParentGuid>
   </Form>
GeneralHelp with implementing a monthcalendarmemberFuXXz26 Oct '10 - 1:18 
Hello,
 
at first your work is really great. But now, I have a problem and I need your help.
The situation is the following:
 
I implemented a monthcalendar on a dockform.
Furthermore I docked the form at the container.
When I minimize the mainwindow, which implemts the dockcontainer, I get this error:
(An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll
Additional information: Der Wert -1 ist für LargeChange ungültig. LargeChange muss größer als oder gleich 0 sein.)
 
When I set the monthcalendar invisible or when the form with the calendar isn't docked, no error occurs.
 
Do you already know this problem, or better, do you have any suggestions or solutions?
 
I would be pleased about an answer.
 
Best regards
 
Rebecca
Questionho can I use it with VB.NET?membermfsav215 Oct '10 - 10:38 
I have an app done with VS2010 and .NET 4.0
 
I used VB.NET to develop. I need to make it docking.
Can I use your excellent library?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 2 Oct 2009
Article Copyright 2009 by Cristinel Mazarine
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid