Dockable window in MDIForm

How to write a dockable window form in the mdi windows using VB? I want to write some form which can attach to left or right inside the mdiMain.. just like those properties windows and toolbox in VB IDE.

Thx.

Samuel
LVL 1
LCPAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
You can set the borderstyle of the form you are docking to NONE, then add the following code to a MODULE:

Global Const DOCK_LEFT = 1
Global Const DOCK_RIGHT = 1
Sub Dock(mdiParent As Object, mdiChild As Object, DockArea As Integer)
    Select Case DockArea
        Case DOCK_RIGHT
            mdiChild.Left = mdiParent.Width - mdiChild.Width - 180
        Case DOCK_LEFT
            mdiChild.Left = 0
    End Select
End Sub


In the MDIForm_Resize Event, you can then do:

   Dock Me, Form1, DOCK_RIGHT


Cheers!
0
 
mcriderCommented:
By the way, the code:

   Global Const DOCK_LEFT = 1

Should be:

   Global Const DOCK_LEFT = 0


Cheers!
0
 
LCPAuthor Commented:
Your solution simple and workable, but it is not what I want, may be my question is not specific enough. I want a solution that write less code for the form to be dock left and right, and I hope there is some kind of API call to make my mdichild form to be dockable automatically EXACTLY the same style as those windows like the Project Explorer, Component ToolBox in VB IDE.
Moreover, I found that when I set the ControlBox property of the form to be false, the close windows button on the right upper corner will be disappear also, any solution to do this? In addition, if I set the border style to none, I can't resize and move the window also.

Thx.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mcriderCommented:
Sorry, there's no API to dock windows...

You don't have to set the borderstyle to none with the example, and you will be able to move the window...

If you resize the MDI parent, the child will redock...

Cheers!
0
 
mcriderCommented:
One other thing you can do to keep a border style... use the docking code I gave you and set the MDI Child's MOVABLE Property to FALSE.  That way, the titlebar appears, and the window gets docked, but the user can't move it...


Cheers!
0
 
LCPAuthor Commented:
But I want th window can be controlled by user to move it and dock to left, right and botton. Even I use your code, I still can't do it as there is no event trigger in VB when a Window Move and I can't calculate the new position of the window for docking left, right or bottom.
In VC++, there is a property setting for docking, so I wonder is it any API call for it.

Thx.
0
 
mcriderCommented:
To do that, you have to create a hook to subclass your window with the with the WM_MOVE message...

Check out these two Microsoft Articles:

HOWTO: Build a Windows Message Handler with AddressOf in VB
http://support.microsoft.com/support/kb/articles/Q170/5/70.asp?LNG=ENG&SA=MSDN 
This article demonstrates WM_RBUTTONUP (windows right mouse button up message), but can be adapted to use the WM_MOVE message...


HOWTO: Use APIs to Check, Enable, or Disable Full Window Drag
http://support.microsoft.com/support/kb/articles/Q185/6/37.ASP?LNG=ENG&SA=MSDN 
 


Cheers!

0
 
LCPAuthor Commented:
I have try the Windows Message Handle. It work fine and it can create a Form_Move Event for me. However, is there any Window Message when I am moving the Form before my mouse up event? I have try WM_WINDOWPOSCHANGING, but it doesn't
 work even it was trigger before WM_MOVE. Moreover, can I change the size of the shadow frame of the moving windows when I moving the window?? If there is such event can be trigger, my dockable window inside the mdiform can work much perfect.
:>

Thx.
0
 
mcriderCommented:
Which event are you checking the hook in?  Please post a snippet of your code so we can see how you've implemented the hook...


Cheers!
0
 
mcriderCommented:
Just checking back... You still there?


Cheers!
0
All Courses

From novice to tech pro — start learning today.