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

A Visual Studio 2005-like Interface

By , 22 Jan 2007
 
Sample Image - DockPanelSkin.png

Overview

It's now been awhile since programs like Opera, Firefox and other software introduced MDI tabbed interfaces. Unluckily, there are not too many free components that allow .NET developers to create such interfaces. I was searching the internet for a long time before discovering the DockPanel Suite, a wonderful and fully customizable component from Weifen Luo. This component is available on Sourceforge, here.

Introduction

This article shows how the DockPanel component can be customized, implementing an Extender class. The attached example creates a Visual Studio 2005 like interface against version 1.0 of the DockPanel.

Copyright

Weifen Luo is the owner of the copyright for the DockPanel Suite, which includes the Extender class, the object of this article.

Background

This article is based around the DockPanel Suite library and it requires at least a basic knowledge of this. Please refer to the References paragraph to find more information about it. A good knowledge of the System.Drawing classes and functions is also required.

The Extender Class

DockPanel accepts customizations through five classes:

  • AutoHideTab represents a single tab used when the content is in the autohide state.
  • AutoHideStrip draws tabstrips and tabs when the content is in the autohide state.
  • DockPaneCaption draws the caption pane when the contents are tool windows.
  • DockPaneTab represent a single tab used when the content is a document window or a tool window.
  • DockPaneStrip draws tabstrips and tabs when the content is a document window or a tool window.

For convenience, these classes are enclosed in an Extender class. The following sections describe the component parts and the relative modules you can customize.

AutoHideStrip and AutoHideTab

The autohide strips can appear at the four borders of the main form and they are activated by the MouseOver event. The tabstrip will be visible only if at least one content is in the autohide state. When the tabs are docked to the left or to the right, the resulting tabs are rotated 90 degrees.

Following is a screenshot of a form docked to the top:

Here is another example of a form docked to the bottom:

The drawing of tabstrips and tabs is done by the class AutoHideStripFromBase. The painting methods are mainly the following:

  • OnPaint handles the OnPaint event of the control.
  • DrawTabStrip draws the tabstrips with a right orientation and all the contained tabs.
  • DrawTab draws a single tab.

DockPaneCaption

DockPaneCaption represents the form border when the form is docked and it normally contains a title, a button to close the window and a button to set the window to the autohide state. The Visual Studio 2005 like interface also contains a button to manipulate the window state through a context menu.

The following is a screenshot of DockPaneCaption:

The drawing of the caption is done by the class DockPaneCaptionFromBase. The painting methods are mainly the following:

  • OnPaint handles the OnPaint event of the control.
  • DrawCaption draws the background and the caption text.

DockPaneStrip and DockPaneTab

DockPaneStrip represents the tab area shown when the content is a tool window or a document. There are many differences between these two regarding the tab shape and other behaviour. An example is hiding the tabstrip in the case of a single content. The drawing of tabstrips and tabs is done by the class DockPaneStripFromBase. The following examples will clarify these differences.

Example of a tabstrip that shows document tabs:

Example of a tabstrip that shows document tabs with an icon and the overflow symbol:

Example of a tabstrip that shows tool window tabs:

The painting methods for the document tabstrip are the following:

  • OnPaint handles the OnPaint event of the control.
  • DrawTabStrip_Document draws the background.
  • DrawTab_Document draws the shape, icon and text.

The painting methods for the tool window tabstrip are the following:

  • OnPaint handles the OnPaint event of the control.
  • DrawTabStrip_ToolWindow draws the background.
  • DrawTab_ToolWindow draws the shape, icon, and text.

Using the Code

To apply the Extender to an instance of DockPanel, insert the following code into the Form_Load event of your form, replacing the name of the control with yours.

Extender.SetSchema(DockPanel1, Extender.Schema.FromBase)

Final Notes

I hope that you find this article useful. If you find this article stupid, annoying or incorrect, express this fact by rating the article as you see fit. In the end, you're very welcome at any moment to freely contribute to this project by suggesting improvements or by submitting code or other materials.

Credits

Thanks to Weifen Luo for providing the community with the DockPanel component. If you like this component, you may want to make a donation to Weifen Luo here.

References

History

  • 3rd June 2006: first submission
  • 20th July 2006: bug fix (the MdiParent property doesn't need to be set)
  • 20nd January 2007: updated download

License

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

About the Author

Danilo Corallo
Web Developer
Italy Italy
I am 29 years old and I've been working with C++, Visual Basic .NET, C# and ASP.NET. I have a large experience in Industrial Automation solutions, but I've worked also as Web developer and DBA. I like to share knowledge and projects with other people.

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   
QuestionHow to add forms and controls to themmemberSnehasish Nandy21-Dec-12 0:31 
Hi
 
I just saw the code.please tell me how can i add controls to the form..
i added few at the frmDocument page.but when ever i am taking file->new file, it's showing the same control..
 
please tell me how to add new forms and controls to it..
Questioni need a tutorialmembervahnvallain30-Aug-11 20:17 
Confused | :confused: can you make a tutorial OMG | :OMG: pls Cry | :((
GeneralMy vote of 5memberE$w@r24-Feb-11 17:51 
Nice work
GeneralMy vote of 5memberalifellod4-Nov-10 10:04 
very good,thanks
Generalconvert this code to C#membersa.alavifar23-Oct-10 22:07 
this code is very usefull and i did convert to C# but i have a problem ; how can i show child form in DockPanel once a time , i mean when i click on the button show only one child form in dockpanel beacuse in c# code you must create a new object from form;
for this problem i wrote this code :

 

foreach (Form f in Parent.MdiChildren)
if (f.Name == Child.Name)
{
f.Select();
return;
}
Child.MdiParent = Parent;
Child.Show(DockPanel);
 

 
but i saw this error :

Error creating window handle.

please help me .....
GeneralMy vote of 5membersa.alavifar23-Oct-10 21:59 
perfect
GeneralUnable to set max size of form without grey strip running along the bottommemberLindseyTantrum3-Sep-10 3:09 
Hi there,
 
I've been stuck on this one for a while. I have a form that's similar to the properties toolbar which is docked along the top of a mdi container.
 
I've set the maximum height of the form using the following syntax
 
this.MinimumSize = new Size(0, 180);
this.MaximumSize = new Size(Screen.AllScreens.Max(s => s.Bounds.Width), 180);
 
Thing is the form resizes correctly but there is a large grey strip running along the bottom.
 
How can I get rid of this strip running along the bottom, or resize it to the same size as the form?
 
When I comment out the code above, the grey strip does not appear, but then my form is too long.
GeneralRe: Unable to set max size of form without grey strip running along the bottommemberLindseyTantrum23-Sep-10 0:38 
I figured how to stop this by setting the AutoHidePortion property of the form. This sets the form's height correctly without the extra space. Shucks | :->
QuestionPaint TitleBarmemberEugene Kogel23-Apr-10 16:12 
I have created several windows of type WeifenLuo.WinFormsUI.Docking.DockContent. When windows docked left, right, top and window they display Toolwindow style title bar. Window, docked to the "central dockpoint" doesn't display the title bar looks like Visual Studio code windows - without the title bar and with a TAB. My questions are: does this window has title bar at all, if yes, can I use custom painting to paint it instead of tabs so it will look exactly like all other windows, is it DockContent form for which I want to overwrite WndProc using WM_NCPAINT message?
 
Thank you very much
GeneralWorking with WeifenLuo.WinFormsUI.Docking.dll version 2.2.0.0membernisad13-Oct-09 4:24 
Hi Daniel,
 
I am trying to use your extender with WeifenLuo.WinFormsUI.Docking.dll version 2.2.0.0 but there are issues with classes AutoHideTabFromBase Inherits AutoHideTab and DockPaneTabFromBase Inherits DockPaneTab which are not defined in version 2.2.0.0 (AutoHideTab and DockPaneTab). Could you please tell me where I should inherit from in the version 2.2.0.0 to make it work?
 
Thank you,
Nisad.
Questionwill this work with Visual Basic 2008 Express Edition?memberMember 363971330-Sep-09 14:39 
I can't see how to do this under the Express version?
 
Cheers,
 
Richy
QuestionEvent Problem? No LostFocus and Leave Events on floating Windows?memberSkeletor2314-Sep-09 4:51 
Hi,
 
i'm not sure if this is a bug or if I have wrong understanding of the events.
 
I simply want to validate the currently editing window, if the user clicks somewhere else.
I use the Leave-Event of the current window to start Validation.
 
This works fine if the window is docked, but as far at it is floating I get no Leave and now Lost Focus events??
 
Or is there a better way to start validation?
 
Thanks and Regards, Daniel
GeneralFor hide tab when have a single DocumentmemberPasalino9-Sep-09 3:40 
For hide tab when we have a single document, we must create a new class that inherit DockPaneStripBase and a class that implements DockPanelExtender.IDockPaneStripFactory and assign them to a DockPane
This is an example:
 
public class DockStripExt : DockPanelExtender.IDockPaneStripFactory
{
#region IDockPaneStripFactory Membri di
 
public DockPaneStripBase CreateDockPaneStrip(DockPane pane)
{
return new DockPaneStripFromBase(pane);
}
 
#endregion
}
 
[ToolboxItem(false)]
public class DockPaneStripFromBase : DockPaneStripBase
{
 
public DockPaneStripFromBase(DockPane pane):base(pane){
}
 
protected override void EnsureTabVisible(IDockContent content)
{

}
 
protected override GraphicsPath GetOutline(int index)
{
return null;
}
 
protected override int HitTest(Point point)
{
return 0;
}
 
protected override int MeasureHeight()
{
return 0;
}
}
 
In the interessed panel:
 
contenitoreDock.Extender.DockPaneStripFactory = new DockStripExt();
QuestionHow can i change automatically all locale files used in each one of the forms ?memberagelospanagiotakis31-Aug-09 0:33 
I created my application with this fantastic way.
Now i am in the face of making it multilingual.
How can i change automatically all locale files used in each one of the forms ?
This code won't change the resx files used in each of the forms.... but only int the main.
 
culture = New CultureInfo(localeName, True)
'culture = CultureInfo.CreateSpecificCulture(localeName)
My.Application.ChangeUICulture(localeName)
Thread.CurrentThread.CurrentUICulture = culture
Thread.CurrentThread.CurrentCulture = culture
 
Any help will be appreciated!
QuestionHow Can I Impement Dock content to Left by Extendering the DocumentTabStripLocation Enumerable with Adding Left property?memberhjzhou29-Aug-09 21:12 
Dear weifenluo,
 
Thanks for Share this useful UI Components!
I Want to Add a NavigationForm with AutoHide Property in MainForm left.This NavigationForm include
some Dockcontent and I wish this Dockcontent Form can line top to Bottom,but not left to right.
So I try to Modifiy your code by Adding a "left" member to DocumentTabStripLocation Enumerable Type.
I have spent two days in doing it,As a Result, I can't finish it with a good effect.
If you can help,I will grateful.
Best Regards.
 
huajun Zhou
09.8.30
Generalgreat work. =)memberfrancis314-Aug-09 22:40 
a lot of credit for you. hehe
 
i am not a programmer..but i want to learn, can you give me a little code for c#? anyone here, please? =)
 
best regards.ö
GeneralCommunication between docksmemberhakimgada5-Jul-09 21:20 
Hi,
 
I needed help on being able to transfer values across the dock windows.Lets say I need to add name in document dock when someone select a value from combo box in different dock window.
 
How can that be achieved.
 
Please help
 
Regards
GeneralDoubts.. wud be sweet if someone cud help me , pleasememberGagan111813-Jun-09 15:43 
Hi there ,
I had two doubts please ,
 
First --
I would like NOT to allow the user close the docked windows.. is there a way , i can disable the "x" on the docked windows.Yeah i know , its strange, but that is what the client wants... Smile | :)
 
Secondly--
Is there a way, I can set the focus back to one of the child forms .. currently Now I am employing a workaround by creating child controls in a serial manner.. but that is NOT the way i want.. i would like to create child forms in any manner , I may like , and i would like to set the focus back to the child i created second.. there must be a way.. i know , I am missing something ...
 
Guys, thanks for any help ... and yeah i know , i deserve a finger for asking stupid questions, eh ! Wink | ;)
Generalimplement VOIPmembermzamoandris1-Jun-09 4:05 
HI MATES
HOPE U CAN HELP ME I WANT TO IMPLEMENT Voice Over Internet Protocol IN MY PROJECT CAN ANYONE ASSIST ME CAN Smile | :)
Questionhow to doc different formsmemberghalibkhan14-May-09 22:05 
I would like to use this component. I want to display different type of forms. How can I do it please tell me
General[Message Deleted]memberNoKindOfName21-Mar-09 18:56 

GeneralRe: How to add thingsmembersndwchmkr2-May-09 13:08 
use the latest version of Weifen Luo dockpanel suite
 
WeifenLuo.WinFormsUI.Docking.dll with VB.net 2008
Add control to toolbox by adding the dll under general
drag and drop onto Main Form
import on main form.vb
Imports System.Windows.Forms
Imports WeifenLuo.WinFormsUI
set isMDIcontainer to True
on sub forms
import in subform.vb
Imports WeifenLuo.WinFormsUI.docking
Under public class subform enter
Inherits DockContent
under the subform.designer.vb
replace: Inherits System.Windows.Forms.Form
with : Inherits WeifenLuo.WinFormsUI.Docking.DockContent
Code to use now is:
Form2.TabText = Form2.Text
Form2.Show(DockPanel1)
GeneralRe: How to add thingsmembersndwchmkr2-May-09 13:09 
read:
 
http://sites.google.com/site/myvbnetnotebook/weifenluo-winformsui-docking-dll-with-vb-net-2008[^]
QuestionThank you!memberMorgan19819-Feb-09 4:08 
This code is awesome and has been very usefull.
 
I have a question regarding the FloatPanel.
 
I would like to be able to manipulate the size / location of the form from my code while it is not docked as a tab. However when I try to set the location property of the panel, while the values change in the code, the panel stays exactly where it is on the screen?
 
If anyone could offer some assistance it would be greatly appreciated.
 
Thanks
Michael
AnswerRe: Thank you!memberPCBuilder15-Mar-09 5:37 
I have been using the DockPanel suite for few years now and have had a few instances where this was a requirement. I couldn't ever get it to work from within the suite. I eventually settled on using API calls (GetWindowRect and SetWindowPos).
GeneralMore than 10 tabstrips that shows in tool window tabs which becomes hard to seemembereet7631-Dec-08 1:42 
Is there a way to create an option button containing list of tool form beside tabstrips on the bottom of Tool window when creating large number of tool windows?
 
If my application create more then 10 tool windows, the tabs on the bottom becomes hard to see because these tabs overflow the current tool windows size.
 
any idea how to do better ?
GeneralDocking fails on a NON-maximized windowmemberstmarcus6-Oct-08 16:04 
Hi, this docking system works perfectly on a maximized window, but when the window is in any other state, it fails completely. The docking cues draw all the way off the window (as if they are trying to draw maximized even when the window is not in that state), the windows get shoved all the way off the parent form (again, as if they are trying to position themselves onto a maximized form), the windows themselves misbehave (cannot move the splitter in most locations), and also mis-draw (many lines are missing between windows).
 
I compiled under Visual Studio 2008, but it seems hard to believe that could cause this problem.
 
I am running Windows Server 2008 as my home workstation. Could that be the issue?
 
Has anyone else experienced the same difficulties?
QuestionRe: Docking fails on a NON-maximized windowmemberJeff Bowman7-Nov-08 15:32 
Hi StMarcus
 
Have you found a solution to this problem yet?
 
Thanks,
Jeff
Generalerror on closing applicationmembermigserra5-Sep-08 7:06 
hello
after working with this i start having erros on closing app
anyone have same problem ?
 
i found new version of dll on
http://www.softpedia.com/progDownload/DockSample-Download-74185.html[^]
but is different, i got errors ( related with cross thread, and i dont use threadssssss )
 
anyone cam help me?
 
tanks
Generalstay first default document openmemberMember 11476654-Sep-08 8:16 
very good job
 
tanks
 
when closing documents, they close, ok, but if want 1 document, default, that dont close ??
 
is it possible?
 

good coding
GeneralWeifenLuo.WinFormsUI.Docking.dll with VB.net 2008memberuser000000000110-Aug-08 20:28 
Can i use the dll with vb.net 2008 ?
GeneralRe: WeifenLuo.WinFormsUI.Docking.dll with VB.net 2008memberofwood24-Nov-08 12:25 
this worked like a charm for me with VS2008
Generalc#membercakirhal28-Jul-08 20:27 
What about c# code? I am using DockDotNET but I saw that this library is better than it. So I want to change my library. I am using C# and want to know if this project is written in c# alternatively VB .NET. thanks.
Questionhow can i put a dock content on top of another during formloadmemberjeipiyaku24-Jul-08 23:06 
need to know how to do it
 
something like the left side of this pic
 
http://i111.photobucket.com/albums/n159/jeipiyaku/howto.png[^]
GeneralUpdating Status BarmemberAlexander Higgins21-Jul-08 17:54 
First, I would like to say Great Job!!!
 
I was working on an interface just like this for my own projects when I ran across this. I will be using this interface in the next version of IIS Log file parser, which is currently in the midst of being reworked.
 
However, I can't seem to figure out how to set the status label text... Do I need the source of the dock panel dll??
 

GeneralAuto Arranging documentsmemberrolf.evenblij@alice.nl14-Jul-08 23:41 
Hi there,
 
A perfect component!
 
However, I have on question. One can manually re-arrange tabbed documents by means of drag and drop. Is there a way to do that programmatically?
I'm creating an app with lots of master-detail relations which would benefit from such on option.
Big Grin | :-D
GeneralHimemberT. Ravindran11-Jun-08 19:05 
Hi, I am using this dll, it was really nice.
If we shown a form in left side like tool box, if i close that tool box and again i open it there. That time the tool box width is taken default width, is there any possible way to change that width at the time loading.
GeneralHi.... DockPaneStrip - how to hide the tabstrip in the case of a single contentmemberMirjan19-May-08 3:14 
Can anyone please tell me how to hide the tabstrip in the case of a single content.
I will be very greatfull for an example.
 
Thx.
 
Mirjan.
Generalsuport for RTL.memberCSharpDevelopers13-May-08 9:14 
Thanks. but your theme dos'nt support RightToLeft Layout.
How can resolve this problem?
Generalthanks a lot!memberfast200812-May-08 21:53 
nice job! I'v learnt a lot from it . Smile | :)
GeneralMapPoint and dockingmembermmjc2329-Feb-08 3:26 
Hi and great work!
I have a problem with my AxMapPointControl v.13, when I dock my DockPane containing MapPoint control, my map closes.
Maybe it's a matter of COM objects, do you have any idea?
 
Thank you!
GeneralAvoid Close for the DockPanel [modified]memberseasea31-Jan-08 20:38 
Hi,
 
Is there possible to hide the close button for the dockPanel ??
 
Is there possible to show the childForm only one time???
 
thanks
 
modified on Friday, February 01, 2008 5:50:31 AM

GeneralCommunication between panelsmemberBrandon Nason13-Dec-07 3:31 
I'm working with this library but can not for the life of me figure out how to get information in one panel to the other panel. Any help would be greatly appreciated.
GeneralRe: Communication between panelsmemberlextm2-Feb-08 2:08 
Because in most cases non-document panels can be singletons, you can follow the GoF suggestion to implement the pattern. In that way, you can access panel singleton easily because they are global visible.
GeneralRe: Communication between panelsmemberDanilo Corallo15-Apr-08 22:44 
Hi!
My suggestion is to RaiseEvents from child forms to the main form and dispatch from the main form, messages to other forms. I believe is the most elegant solution
Kind Regards,
D.
GeneralVS2005 like tabbed interfacememberirfan.hafid15-Nov-07 12:55 
Thank you for your artikel, this help me as beginner
 
Irfan

GeneralChange the Back colurmemberdanasegaranea31-Oct-07 19:34 
Hi ,
How can i change the back colour of the main tab.
 
Dana
Newstoolstripcontainer + dockpanel solutionmemberXDG6-Oct-07 2:43 
quote from http://sourceforge.net/forum/forum.php?thread_id=1834495&forum_id=402316
 

The problem is that the MDIClient is below toolStripContainer in the Z-Order the the solution from Erick Ellisover at the MSDN forums is:

http://forums.microsoft.com/msdn/showpost.aspx?postid=14593&siteid=1

"The best way to get what you want is to use ToolStripPanels instead of ToolStripContainer - you have to add these to the toolbox via Choose Items... command off the context menu in the toolbox. The design time experience with ToolStripPanel is pretty raw - it will autosize down to zero size pretty easily and docking them in the right order is critical After you add these to the toolbox, dock them to the top, bottom, left, right in the correct z-order (use document outline). This should provide the operation and appearance you want for MDI and repositionable toolstrips. Hope this helps."
GeneralRe: toolstripcontainer + dockpanel solutionmemberheadkaze9-May-11 19:19 
Thanks for the info it was very helpful!
GeneralAuto Arranging Tabs in DockState.Document AreamemberViaboom9-Sep-07 23:13 
I've looked in all forums with no luck so any help is appreciated.
 
I love the dock panel flexibility but it can get messy in a hurry with users unfamiliar with how to use it. I want to add on auto arrange function that puts it all back like new without closing and reloading forms and losing info. A simple loop through the DockPanel.Contents takes care of most of this except the forms in the "Document" state. If I end up with two or more tab windows side by side with one or more tabs in them, I can't seem to programatically get them all back lined up into one window.
 
I am working with the VB version on this page, any suggestions?

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 22 Jan 2007
Article Copyright 2006 by Danilo Corallo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid