Click here to Skip to main content
15,612,595 members
Articles / Containers / Docker
Posted 23 Sep 2008


21 bookmarked

Form Docker

Rate me:
Please Sign up or sign in to vote.
2.33/5 (4 votes)
23 Sep 2008CPOL2 min read
Form Docker is a class library (DLL) that can dock any form to different parts of the screen.


This class library can dock any form, on different parts of the screen. It acts just as the Dock property of a control acts, only with more options. Not only can this class library dock to the top, bottom, left, right, and fill, it can also dock to corners of the screen (top right, bottom left, etc.). It can also leave space around the edges of the screen, using the Padding property.


While updating one of my projects, I found I was writing a lot of code for keeping the form in a certain place over and over again. I decided to write this class library to make it easier to keep forms in specific spots, and because I think it can be quite useful. If controls can be docked, why can't forms be docked?

Using the Library

The class library is provided as a DLL that can be referenced from your project. For those who don't know, you can add a reference by choosing "Add Reference..." from the "Project" menu and then selecting "Browse" to find the file.

Once referenced, you will need to create a new instance of the FormDocker class:

Dim Docker As New FormDocker.FormDocker(Me, _
           FormDocker.FormDocker.FormDockMode.Top, New Padding(5))

If you wish to take advantage of the events in the class, it can also be declared using WithEvents:

WithEvents Docker As New FormDocker.FormDocker(Me, _
           FormDocker.FormDocker.FormDockMode.Top, New Padding(5))

The first parameter represents the form to dock. The second is where to dock it, and the third is the padding. There are also optional parameters.

Once declared, the form will automatically be docked. The docking can be re-applied, that is the form re-positioned, any time, by using Refresh():


To undock the form, use UnDockForm(). To dock the form again, use DockForm(). These are equivalent to Dock = False and Dock = True.

'Undock form:
Docker.Dock = False

'Dock form:
Docker.Dock = True

Feel free to explore other parts of the library, everything is commented. If you have any questions about how to use this library, please post a comment.


  • 23/09/08 - Version 1.0 released.


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

Written By
Canada Canada
I am a hobby VB programmer.

Comments and Discussions

GeneralMy form does not move Pin
eusta5-Feb-09 4:13
eusta5-Feb-09 4:13 
GeneralWeifen Luo DockPanel Suite Pin
pinx26-Oct-08 9:05
pinx26-Oct-08 9:05 
GeneralRe: Weifen Luo DockPanel Suite Pin
Programble26-Oct-08 9:13
Programble26-Oct-08 9:13 
Questionso what ? Pin
wakashich23-Sep-08 23:42
wakashich23-Sep-08 23:42 
AnswerRe: so what ? Pin
Programble27-Sep-08 5:39
Programble27-Sep-08 5:39 
Thank you for your feedback. I will try to resolve as many problems as possible, and release a new version.

I realize that when the form is resized or moved, there is a flicker, but I do not know how to stop that. If anyone know of how to prevent flicker, please post a comment.

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.