Floating toolbars

IfYouSaySo

Well-known member
Joined
Jan 4, 2006
Messages
102
Location
Hermosa Beach, CA
Programming Experience
3-5
Has anyone implemented or seen floating toolbars, like what Visual Studio uses? Example would be any of the debug windows, like watch or output windows. They can either be docked to an edge, or if you drag them, they will float like a child window. I've always thought they were neat, but when I've tried to implement them I always get stuck. If anyone has general ideas on how it might be done, I'd like to hear that also.
 
They are MDI childs, to get the appearance you can set the Form.FormBorderStyle to FixedToolWindow or SizeableToolWindow. The docking you just provide logic code to achieve. Say it's moved within 10 pixels from MDI parent border, you set the toolbar locoation to 'click' into place, and when dragging it yu don't let it release until mouse drags it 10pixels out of it's position.
 
Alright, I'll try to implement it for the 10th time this weekend. I'll let you know how it goes.

By the way, what do you mean by this part: "you set the toolbar locoation to 'click' into place". I think I have a half implementation at home. I'll have to look at if I was doing it this way, and where I got stuck specifically.
 
pseudo code, ex. 10px to border:

onmousemove
if child.left position is < 10 then child.left=0
 
Okay, so I started to look at this again, and some of the issues are coming back to me.

1) The MS floating toolbars aren't really child windows, at least not when they're floating. They can be moved partially outside the main (parent) window, but they always are in front of the parent. I did some research and realized that this effect could be achieved by setting the .Owner field of the floating toolbar to be equal to the Parent. When the toolbar is docked, I think it switches to being a child of the parent via .MdiParent. I think I have this pretty well covered.

2) When the toolbar is floating, the .FormBorderStyle = SizableToolWindow, but when it docks, it appears to be .FormBorderStyle = None, with a custom drawn title bar, and the docked form is actually resizabe. What to do about this I'm not sure--because .FormBorderStyle = None does not allow resizing, but all the styles that allow resizing give you a standard title bar. I'm wondering if I can do style = None, and then make an unmanaged call to SetWindowLong to set a style such as WS_SIZEBOX to get a custome window style. But I was unsure of that even, because the docs on SetWindowLong say they don't have an effect if you set the style after the window is created (except in certain limited cases). Any ideas on this? For the custom title bar, I was just going to add a panel, have it dock to the top, and add a close button, and wire it so that setting the text adds text in that panels client area.

3) Not really a problem, but the form doesn't actually dock until the mouse is over top of the edge of the main window (it doesn't dock when the edge of the floating toolbar is next to the main window). So I wasn't sure here what handler to use to trap this condition. Basically I have the mouse down, and dragging the floating toolbar, and the mouse coordinate equals the main window edge at some point. Any clues on what handler I need to use?

4) Another different behavior of these floating toolbars is that when you move them, the actual toolbar isn't moved--it stays where it's at until the mouse up event. Instead, you get a rectangle outline of where the toolbar will end up--so it's this outline of the toolbar that you actually see snap into place. The same goes for a docked toolbar that you are un-docking--the actual toolbar stays docked, but you see this outline of the undocked toolbar that you can move around. And when it finally gets the mouse-up event, then the toolbar actually undocks. To be honest, I have absolutely no clue how to get this effect--is this some standard effect or is it neat custom code that MS came up with? Any ideas on how to reproduce it?

5) And then there's the push-pin button at the top, which adds even more custom behaviours that I don't even want to think about right now. I'll be happy if I can get the other stuff.
 
Just downloaded an MFC sample from MS, and pretty much confirmed that the functionality described in point (4) of my previous post is produced by the MFC CRectTracker class. Not sure if there is a .NET equivolent. Or maybe CRectTracker is wrapping some COM API that I can take advantage of. Anyone know the details?
 
Your right, they are not mdi childs, but the same docking logic should apply inside 'parent' (possibly specific docking areas) and on the outside if you mind the well known Winamp docking style.

Changing appearance when docked or not should be viable.

As it goes for borderless forms and custom title etc those can have custom window dragging too. ( http://www.google.no/search?hl=no&q=vb.net+move+borderless+form&meta== ) and custom resize code logic ( http://www.google.no/search?hl=no&q=vb.net+resize+borderless+form&meta== )

I'm not sure if your number4 is caused by your operating system setting. When I drag windows they do move, I don't see no frame.. In XP Control Panel, System Settings, Advanced, Performance you got the checkbox for "Show window contents while dragging" usually adjusted automatically for best system performance..
 
Floating Things

I have Toolbox, Properties Window, Solution Explorer and Index(MSDN) on top of one another and are individually selected by tabs. I can move this collection around the design area as well as changing its size. Most useful. I got it by chance and sometimes they do seem to please themselves! Right-Click the top of each and Tick "Dockable" and twiddle to sit them together. Also, adjust settings on the My Profile tab on the Start Page. Experiment with these things.
Best of Luck.
 
TwoWing: The "tabbed" interface you describe is consistent with what I have seen when you click the push-pin on one of these windows. Very nice, but I'm not going to try and emmulate that behavior just yet.

JohnH: The links look interesting, it should solve most of the problems with point 2. For point 4, it doesn't appear to be a system setting, because if I create normal windows with vb.net, they redraw when I move them as I would expect. It's only these Visual Studio windows that act this way. Also, as I noted in a prior post, the functionality matches almost exactly what is provided by an MFC (c++) class CRectTracker. Fortunately, MS distibutes the source code for MFC with visual studio, so it should be possible to port that class to VB.NET.

I think I'll concentrate on getting 1,2,& 3 done first, then worry about re-writing CRectTracker later. Anyway, that should give me most of the features.
 
Back
Top