Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#

Visual Studio IDE like Dock Container

Rate me:
Please Sign up or sign in to vote.
4.38/5 (41 votes)
14 May 2009Public Domain2 min read 372.7K   21.4K   256   91
Free Windows dock container

Important Note

We intend to create a new release of this open source product at the end of the next month (June 28, 2009). Please send any bug you've found (or desired change request) at contact@osec.ro .

Thank you all for using this product.

Introduction

This article describes how to use the free dock container library in your applications.
You can download the full source from here. The full documentation for the product can be accessed here.

Here is a image of the sample project of this application:

Crom

Background

This user control is made in C# and allows docking child forms on Left, Right, Top, Bottom and Fill.
The dock is guided by dock guiders.

Using the Code

There are two important classes in this library: DockableToolWindow and DockContainer.

The DockableToolWindow is the base class for the tool windows.

The most important property from this class is AllowedDock. This property returns the allowed dock values for the tool window which specializes this class. By default, this property allows docking the tool window on all panels. Overriding this property can change the dock behavior of the tool window (for example can allow only dock left or right).

The DockContainer class is the user control which hosts the tool windows.

This control should be added to the main form and docked fill.
Then you can add forms to it using the Image 2AddToolWindow method. This method adds a tool window to be managed by dock container. The caller must show the form to make it visible.

C#
private void ShowNewForm ()
{
   // Create a new instance of the child form.
   DockableToolWindow childForm = new DockableToolWindow ();

   // Add the form to the dock container
   _dockContainer1.AddToolWindow (childForm);

   // Show the form
   childForm.Show ();
}

The forms can be added and docked with a single call to the Image 3DockToolWindow method.

C#
private void OnCreateNewToolWindowDockedLeft (object sender, EventArgs e)
{
   // Create a new instance of the child form.
   DockableToolWindow childForm = new DockableToolWindow ();

   // Add and dock the form in the left panel of the container
   _dockContainer1.DockToolWindow (childForm, zDockMode.Left);

   // Show the form
   childForm.Show ();
} 

The tool windows can be undocked using the Image 4UndockToolWindow method. Here is a sample of how to un-dock the top level tool-window from the left panel and then move it to an arbitrary location:

C#
DockableToolWindow toolWindow = _dockContainer.GetTopToolWindow(zDockMode.Left);
if (toolWindow != null)
{
   _dockContainer.UndockToolWindow(toolWindow);
   toolWindow.Location = new Point(300, 100);
}

It is important for the users of this library to use the Image 5MinimumSizeChanged event to enforce the minimum dimensions of the container form.

C#
private void OnDockContainerMinSizeChanged (object sender, EventArgs e)
{
   int deltaX = Width  - _dockContainer1.Width;
   int deltaY = Height - _dockContainer1.Height;

   MinimumSize = new Size (
      _dockContainer1.MinimumSize.Width  + deltaX,
      _dockContainer1.MinimumSize.Height + deltaY);
}

Points of Interest

The full documentation of this product can be accessed at the site mentioned at the beginning of this article. Please contact us at contact@osec.ro for additional information.

History

  • First version of this product was released on 2008.05.07

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionBug 1 and about 2 kind improvement programs Pin
seeper16-Jun-08 23:44
seeper16-Jun-08 23:44 
AnswerRe: Bug 1 and about 2 kind improvement programs Pin
Cristinel Mazarine1-Jul-08 22:01
Cristinel Mazarine1-Jul-08 22:01 
QuestionTabButton TextRenderer problem Pin
el Golem7-Jun-08 8:35
el Golem7-Jun-08 8:35 
AnswerRe: TabButton TextRenderer problem Pin
Cristinel Mazarine9-Jun-08 8:03
Cristinel Mazarine9-Jun-08 8:03 
GeneralRe: TabButton TextRenderer problem Pin
TimMcQueen29-Dec-08 7:37
TimMcQueen29-Dec-08 7:37 
AnswerRe: TabButton TextRenderer problem Pin
Cristinel Mazarine15-Jan-09 12:55
Cristinel Mazarine15-Jan-09 12:55 
GeneralRe: TabButton TextRenderer problem Pin
strangeloop4-Jan-09 3:36
strangeloop4-Jan-09 3:36 
AnswerRe: TabButton TextRenderer problem Pin
Kompiler17-Sep-09 1:29
Kompiler17-Sep-09 1:29 
I believe this is caused by having ClearType enabled.

To fix it, call the TextRenderer.DrawText overload that accepts a backColor argument and set it to be your controls backColor.

Regards
GeneralRe: TabButton TextRenderer problem Pin
nekimiro8-May-14 23:30
nekimiro8-May-14 23:30 
GeneralDockStyle.Fill doesn´t work Pin
Michaelgor31-May-08 6:11
Michaelgor31-May-08 6:11 
GeneralRe: DockStyle.Fill doesn´t work Pin
Cristinel Mazarine2-Jun-08 7:35
Cristinel Mazarine2-Jun-08 7:35 
GeneralRe: DockStyle.Fill doesn´t work Pin
Michaelgor2-Jun-08 8:06
Michaelgor2-Jun-08 8:06 
AnswerRe: DockStyle.Fill doesn´t work Pin
Cristinel Mazarine2-Jun-08 10:49
Cristinel Mazarine2-Jun-08 10:49 
Generalpls provide demo Pin
Nitin S29-May-08 18:43
professionalNitin S29-May-08 18:43 
GeneralRe: pls provide demo Pin
Cristinel Mazarine30-May-08 7:45
Cristinel Mazarine30-May-08 7:45 
QuestionAdd controls to the DockToolWindow? Pin
gjconely29-May-08 8:12
gjconely29-May-08 8:12 
AnswerRe: Add controls to the DockToolWindow? Pin
Cristinel Mazarine29-May-08 9:24
Cristinel Mazarine29-May-08 9:24 
AnswerRe: Add controls to the DockToolWindow? Pin
aiman6925-Aug-08 23:06
aiman6925-Aug-08 23:06 
GeneralNot working in Vista Pin
muttok19-May-08 22:22
muttok19-May-08 22:22 
GeneralRe: Not working in Vista Pin
Cristinel Mazarine20-May-08 10:31
Cristinel Mazarine20-May-08 10:31 
GeneralRe: Not working in Vista Pin
Member 143090822-May-08 21:03
Member 143090822-May-08 21:03 
AnswerRe: Not working in Vista Pin
Cristinel Mazarine23-May-08 6:26
Cristinel Mazarine23-May-08 6:26 
QuestionBug?? Pin
stuempfig19-May-08 11:53
stuempfig19-May-08 11:53 
AnswerRe: Bug?? Pin
Cristinel Mazarine20-May-08 10:21
Cristinel Mazarine20-May-08 10:21 
GeneralPLEASE add a demo!!!!!! [modified] Pin
Brad Bruce12-May-08 3:58
Brad Bruce12-May-08 3:58 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.