Click here to Skip to main content
15,887,683 members
Articles / Programming Languages / Visual Basic
Article

A Visual Studio 2005-like Interface

Rate me:
Please Sign up or sign in to vote.
4.89/5 (167 votes)
22 Jan 2007CPOL4 min read 1.1M   11K   503   252
Apply a theme that resembles Visual Studio 2005 to the DockPanel Suite, using an Extender class.
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:

Image 2

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

Image 3

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:

Image 4

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:

Image 5

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

Image 6

Example of a tabstrip that shows tool window tabs:

Image 7

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.

VB
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)


Written By
Software Developer (Senior)
Italy Italy
I am 40 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.

Comments and Discussions

 
QuestionHow to use it in other projects? Pin
siegi4411-Jul-06 19:41
siegi4411-Jul-06 19:41 
AnswerFound solution ... [modified] Pin
siegi4411-Jul-06 20:20
siegi4411-Jul-06 20:20 
QuestionRe: Found solution ... Pin
ofwood212-Jul-06 0:13
ofwood212-Jul-06 0:13 
AnswerRe: Found solution ... Pin
siegi4412-Jul-06 6:18
siegi4412-Jul-06 6:18 
GeneralRe: Found solution ...and it works! Pin
ofwood212-Jul-06 13:58
ofwood212-Jul-06 13:58 
GeneralRe: Found solution ...and it works! Pin
siegi4412-Jul-06 19:06
siegi4412-Jul-06 19:06 
GeneralRe: Found solution ...and it works! Pin
Danilo Corallo15-Jul-06 0:51
Danilo Corallo15-Jul-06 0:51 
GeneralRe: Found solution ... Pin
David Kimball6-Oct-06 12:05
David Kimball6-Oct-06 12:05 
Hi, I first want to say thank you for the effort involved with the implmentation of the dockpanel extender. I am new to .Net and have a basic Idea of what it takes to override onpaint and do things yourself ( like make controls ) but its beyond my capability to implment something as powerful as dockpanel with out having to create an extender myself. And I really do not have that capability.

So thank you all for your open source solutions they are prime examples of the ease and connectivity that .net has, they help make it easier for the rest of us to enjoy application development and its greatly appreaciated.

Background

Its only been roughly two weeks since I installed visual studio 2005, feeling that any major development bugs and framework changes have been somewhat finalized and a good time to learn the framework I decided to get the enviornment and a few (thick) books on coding .net applications.

Project

I converted a multiuser ado project done in excel to .net, both applications are relativley the same but sheets in the workbook would be considered forms parent window, and a button would bring up windows forms as a child window ( for running reports, or entering data into the database. ) Very simple, and in a week I had it completed, crystal reports and all.

All I want to do.

All I want to do is take my currently created forms, or if I have to create new forms that use the dockpanel system so they can become floating panels. This will give me a good next step for this project to learn how to move around controls based off resize etc.

The problem is I dont have an understanding of the dockpanel, or the extender. I just want to litteraly copy and paste the sample forms that work in DockpanelSkin and make more of them, customize them, and add file menu items to .Show() them. At that point when I have an instance of a document ill take the steps to understand how it becomes a document panel instead of a properties panel, and how it wants to dock differently to different locations of the sample.

I have tried importing the project DockPanelSkin, with many errors. and spent a good 4 hours trying to find information on why a namespace doesnt show up when a file in my project includes information for the namespace, like the structs.vb file for DockPanelSkin. Well no solution to that.

So I then copy and pasted DockPanelSkin to a new location, and from there imported my project files ( no designer files just for the frmName.vb and any classes that I created ) This resulted in me having to include/reference the System.Data and include crystalreports in the publish project prerequisits area.

This worked, I can hit play and get frmMain from DockPanelSkin to load and do its grace. Or point the startup at my dlgLogin.vb to get the login prompt for my application when then brings up its frmMainWindow. Simple stuff! Adding a variable for the project database connection and yippy skippy DockPanelSkin works along side my project just using the DockPanelSkin project folder name as a side effect ( im ok with that, shrug im learning. )

Now...

How does one go about adding a new form to DockPanelSkin's frmMain? even its from scratch, as long as I can greate a form, and start placing controls on it and do my thing on that form - then make that form one of these panels, like for example another document panel.

I am trying to explain my lack of the understanding, im truely sorry for that. From the looks at the source I see of the document or any of the other child panels there is really nothing to it, just some event handling stuff, and the form which is somehow set as a WeifenLou.WinformsUI.DockContent instead of a System.Windows.Form.

So here is my real question, I cant follow Seigi's instructions because my project's solutions explorer does not show the assembly, or designer, or the forms resx files in it. What do I do? is this somehow a "show all files" type toggle?
This might have helped last night when I was trying to figure out the namespace error when importing the DockPanelSkin to my project, but since my visual studio has never showed assemblies or these designer files I never cared to understand what they contain or how they relate to any code I write or try to import.

Like for example I dont understand what Seigi said here
=====
Now you just have to add the references "WeifenLuo.WinFormsUI.Docking" and "DockPanelSkin" (the extender lib).
=====
Since I imported my project into the sample project DockPanelSkin it has the refence, if it was not there ( like last night doing this vice versa ) I simply add the refence from My Project and point it to the .dll included with the sample project. As far as the and "DockPanelSkin" (the extender lib). I dont understand how the project "DockPanelSkin" is considered an extender lib, I was unable to ever find a way to import anything other then a dll or project, last night when I imported the DockPanelSkin project I already had references from DockPanelSkins My Project to MyProjectIImportedItFrom's My Project and vice versa ( like my project referenced dockpanelskins, and dockpanelskins referenced myproject) im guessing since I imported the project visual studio auto coded and referenced, because it likes to do that.

Am I going about this the wrong way?
From the articles one line of code it seemed it would be very easy to add a new form add that line of code and then make a menu item show the form. But when I add that line of code to a new form I do get errors that the form created by the designer is of a different type then the DockPanel type ( from doing the imports )

The article also said nothing about having to do an imports, or that I would have to dig into the designer.vb code to change its type from a system.windows.form to the dock panel type.

I am sorry this reply is so long, I will edit it as any replys give me a better understanding so I can ask the question better for others checking this articles forum reguarding a simmilar issue they might be experiencing.

In the end my goal if anything is to use the sample project to build an application of dockpanels, I just need to know how to add a new form to the existing sample, from there I can figure it out I hope Smile | :)
GeneralRe: Found solution ... Pin
Danilo Corallo6-Oct-06 12:39
Danilo Corallo6-Oct-06 12:39 
GeneralRe: Found solution ... Pin
David Kimball6-Oct-06 14:10
David Kimball6-Oct-06 14:10 
GeneralRe: Found solution ... Pin
David Kimball6-Oct-06 12:43
David Kimball6-Oct-06 12:43 
GeneralRe: Found solution ... Pin
Greg Cadmes23-Aug-06 8:39
Greg Cadmes23-Aug-06 8:39 
GeneralA tip for VS2005-like Interface Pin
toliscarpenter8-Jul-06 10:19
toliscarpenter8-Jul-06 10:19 
NewsRe: A tip for VS2005-like Interface Pin
Danilo Corallo10-Jul-06 21:59
Danilo Corallo10-Jul-06 21:59 
NewsRe: Source code updated Pin
Danilo Corallo20-Jul-06 2:22
Danilo Corallo20-Jul-06 2:22 
GeneralError Message when Un-Docked Pin
CornellDev27-Jun-06 10:25
CornellDev27-Jun-06 10:25 
AnswerError report.. Pin
Danilo Corallo6-Jul-06 5:07
Danilo Corallo6-Jul-06 5:07 
GeneralSuggestions Pin
Andrey Gliznetsov26-Jun-06 4:10
Andrey Gliznetsov26-Jun-06 4:10 
QuestionChange backcolor for autohide button Pin
kaGyamfi25-Jun-06 23:14
kaGyamfi25-Jun-06 23:14 
AnswerRe: Change backcolor for autohide button Pin
kaGyamfi28-Jun-06 6:50
kaGyamfi28-Jun-06 6:50 
NewsRe: Change backcolor for autohide button Pin
Danilo Corallo6-Jul-06 5:28
Danilo Corallo6-Jul-06 5:28 
AnswerRe: Change backcolor for autohide button Pin
kaGyamfi7-Jul-06 2:40
kaGyamfi7-Jul-06 2:40 
AnswerRe: Change backcolor for autohide button Pin
Danilo Corallo10-Jul-06 22:03
Danilo Corallo10-Jul-06 22:03 
GeneralRe: Change backcolor for autohide button Pin
micmit_syd25-Feb-07 15:08
micmit_syd25-Feb-07 15:08 
AnswerRe: Change backcolor for autohide button Pin
kaGyamfi26-Feb-07 23:47
kaGyamfi26-Feb-07 23:47 

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.