Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split a form? 1

Status
Not open for further replies.

denis60

Technical User
Apr 19, 2001
89
0
0
CA
Hi everybody,

I'd like to split a form in 2 parts with a movable bar in the middle to enlarge or reduce the objects on each side. How is it possible?
 
Do a search for splitter bar.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Get .Net 2005 :p

It has the EASIEST splitter bar I have seen so far...

.Net 2003 sucks, as far as the splitter goes, I never could get it to work right...

BTW, VB .Net express is available as a free beta download at microsoft.com

Check it out, it's pretty cool...

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
CubeE101 -

{nudge}This is the VB6 forum.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I know... but I HATE doing the splitters in vb 6...

It usually takes a blank picture box and a lot of code...

if you want an example in VB6 just start a new project, use the VB Application Wizard... and select:
1) Next
2) Explorer Style, Next
3) Next
4) Next
5) Next
6) Next
7) Next
8) Next
9) Finish

You should get the skeleton for the application with the form visible.

In the main area of the form you will see a TreeView on the left, and a ListView on the right.

If you click right in between them, you will see a selection box in the shape of a narrow rectangle that goes right in between the previous 2 controls and extends the height of both of them...

Look to the property pages, and it should be an Image control, named: imgSplitter

Double click on it to see the code:
Code:
Private Sub imgSplitter_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  With imgSplitter
    picSplitter.Move .Left, .Top, .Width \ 2, .Height - 20
  End With
  picSplitter.Visible = True
  mbMoving = True
End Sub

Private Sub imgSplitter_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim sglPos As Single
  
  If mbMoving Then
    sglPos = X + imgSplitter.Left
    If sglPos < sglSplitLimit Then
      picSplitter.Left = sglSplitLimit
    ElseIf sglPos > Me.Width - sglSplitLimit Then
      picSplitter.Left = Me.Width - sglSplitLimit
    Else
      picSplitter.Left = sglPos
    End If
  End If
End Sub

Private Sub imgSplitter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  SizeControls picSplitter.Left
  picSplitter.Visible = False
  mbMoving = False
End Sub

You will also find more code for this in the Form resize event...
Code:
Private Sub Form_Resize()
  On Error Resume Next
  If Me.Width < 3000 Then Me.Width = 3000
  SizeControls imgSplitter.Left
End Sub

Sub SizeControls(X As Single)
  On Error Resume Next
  
  'set the width
  If X < 1500 Then X = 1500
  If X > (Me.Width - 1500) Then X = Me.Width - 1500
  tvTreeView.Width = X
  imgSplitter.Left = X
  lvListView.Left = X + 40
  lvListView.Width = Me.Width - (tvTreeView.Width + 140)
  lblTitle(0).Width = tvTreeView.Width
  lblTitle(1).Left = lvListView.Left + 20
  lblTitle(1).Width = lvListView.Width - 40

  'set the top
  
  If tbToolBar.Visible Then
    tvTreeView.Top = tbToolBar.Height + picTitles.Height
  Else
    tvTreeView.Top = picTitles.Height
  End If

  lvListView.Top = tvTreeView.Top
  
  'set the height
  If sbStatusBar.Visible Then
    tvTreeView.Height = Me.ScaleHeight - (picTitles.Top + picTitles.Height + sbStatusBar.Height)
  Else
    tvTreeView.Height = Me.ScaleHeight - (picTitles.Top + picTitles.Height)
  End If
  
  lvListView.Height = tvTreeView.Height
  imgSplitter.Top = tvTreeView.Top
  imgSplitter.Height = tvTreeView.Height
End Sub

see what I mean ;-)

In .NET you just create a splitter object, click one side, place some controls in it, click the other side, place some controls in it, and your good to go... :)

MUCH EASIER... [2thumbsup]

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
There are lot's of things that might be considered shortcomings in VB6 that are easy (or easier) to achieve in VB.NET (another example I can think of off the top of my head is console applications). However, I'm not sure that answering a VB6 question with "Do it in VB.NET" is as helpful as it could be...
 
C'mon... I meant it as a joke (yet with a lot of truth to it)... Note the :p above...

but hey it's better than saying...
"Do it in C#..." right ? ;-)

I was offering an option to go check out .Net for free...

I still use VB6 for many things, but as long as MS is gonna let people use VB.Net 2005 Express for free, I suggest you take advantage of the offer... It is a really cool program... 10 fold better then VB.Net 2003 (which I still prefered VB6 over 2003) ...but now 2005 looks a lot more promising...

bottom line,
The reference to how to do splitters in VB6 is above,
VB.Net 2005 Express Beta is a free download so check it out too...

Enjoy, :p
-Josh

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
The following link is for a FREE splitter control for use in VB6 it truely is a great control and better than the .Net version.

MB Splitter

Hope this helps !!!
 
That looks like a nice alternative to all the code above, but it still is not quite as user friendly as the .Net 2005 Splitter control...

For this, you have to manually set what controls are to be assigned to each pane in the Form_Load event, such as:
Code:
Private Sub Form_Load()
    Dim i As Integer
    'set the child controls for the horizontal splitter
    [b]Set HSplitter.LeftOrTopCtl = VSplitter
    Set HSplitter.RightOrBottomCtl = lstDebug[/b]
    'set the child controls for the vertical splitter
    [b]Set VSplitter.LeftOrTopCtl = List1
    Set VSplitter.RightOrBottomCtl = Text1[/b]
    'add some items to the list on the left panel
    For i = 0 To 100
        List1.AddItem "The index of this item is " & i
    Next
    List1.ListIndex = 0
End Sub

To achieve the same results you get in .Net, with 1 double click, you would have to create 2 Picture Boxes, and manually assign them to the panes, to use for containers, where in .Net, the Splitter includes to panes that you can select and use for control containers. Also, you still have to put code in the resize portion to get the splitter to resize with the form, which can be handled via anchors in .Net, the last thing is I could not find a place where you could make one pane stay the same size when you resized the form, in .Net this is done by setting the FixedPane property to Pane1 or Pane2, aside from that, I like it and I'll give you a star ;-)

here is the code I used to make it work:
Code:
Private Sub Form_Load()
    Dim i As Integer
    Set Splitter1.LeftOrTopCtl = Picture1
    Set Splitter1.RightOrBottomCtl = Picture2
End Sub

Private Sub Form_Resize()
    Dim lSplitHeight As Long
    Dim lSplitWidth As Long
    If Me.WindowState = vbMinimized Then Exit Sub
    'set the position/size of the splitter
    lSplitHeight = Me.ScaleHeight
    lSplitWidth = Me.ScaleWidth
    Splitter1.Height = IIf(lSplitHeight < 0, 0, lSplitHeight)
    Splitter1.Width = IIf(lSplitWidth < 0, 0, lSplitWidth)
End Sub

Thanks for the link to the control...

There are a few VB6 programs I have that I wanted to place a splitter in but did not want to mess with all the code...
Nice Alternative!!! [2thumbsup]

Here's your star ;-)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top