VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple Splitter Bar

by Paul Stamp (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

The simplest (as few as three lines of code needed!) and best code to implement explorer-style splitter bars

Assumes
This sample takes advantage of two seldom used features of picture boxes - the Align property and the Resize event. I first discovered this technique when I had an MDI application that was to have a treeview control on the left of the screen, but the right half of the screen should be the workspace where child windows appear. The only controls that can be added directly onto an MDI parent form are those with Align properties - i.e. controls that will snap to the bottom, top, left or right of the screen. Unfortunately the treeview control does not support this, so I added a picture box called "picPane" and set it's Align property to 3 (Align Left). Then I put my treeview onto this picture box - and scratched my head as to how to get it to resize At first I tried some of the solutions put forward on various tips websites, but their solutions were fairly inelegant so I experimented a little bit and hit upon this : Add a new picture box, call it "picSplitter" and set Align property to 3 (AlignLeft), and make the width 60 twips. Set the mousepointer property of the picturebox to 9 (Size WE) Add the following code to the mousemove event of the picturebox : If button = vbLeftButton then picPane.Width = picSplitter.left + X End If This will then fire picPane's Resize event, in response to which you resize your controls on picPane Simple as that ! Of course its not quite as simple as that, but that is the principle. It works because if you move the pointer outside of the boundary of the picture box but have the mouse button pressed, the X property will go negative. Use the X value as an offset from the left position of the splitter bar and because the splitter will "snap" against the picPane picturebox, setting the width of picPane will have the effect of moving the bar as well as widening/narrowing the pane. Trust me.. it works, and not just for MDI forms... it will work for any form, for more than one pane (ie have a treeview and listview, like in Explorer), and for horizontal bars as well as vertical bars.

Rate Simple Splitter Bar

Download Simple Splitter Bar

Download Simple Splitter Bar (2 KB)

Simple Splitter Bar Comments

No comments have been posted about Simple Splitter Bar. Why not be the first to post a comment about Simple Splitter Bar.

Post your comment

Subject:
Message:
0/1000 characters