How to move frames on a form with a sliding control

Posted on 2003-11-24
Medium Priority
Last Modified: 2011-04-14
Say I have two frames on a form.  I want to be able to adjsut the size of the frames by draging an object located between the two forms upwards or downwards.  (like in the IDE to adjust the wifth of the properties windows width for example)

I attempted placing a small borderless frame between. the two frames and made the mouse pointer a NW Size Icon I then tried to change the .top value of the middle frame at the mousedown / mousemove event but my middle frame just jumped all over the place.  If I can move the middle frame smoothly up and down I can easily adjust the heights and tops of the other frames relative to that sliding middle frame...

I thought there was a slidebar or some control but I guess not.

Can anyone point me in the right direction?
Question by:Ficus
  • 3
LVL 16

Accepted Solution

Richie_Simonetti earned 200 total points
ID: 9813175
Sorry, link is broken. I have the zip source code.
Also, you could check this (i don't remember from where comes):

Tip 61: Creating Splitter Bars
Created: April 17, 1995

When designing a Visual Basic® application, you may want to include code that allows the user to resize, for example, two Text Boxes by dragging and dropping a splitter bar. This article explains how to create a program that uses a splitter bar to enlarge or shrink the two Text Boxes to different sizes.

Resizing Text Boxes with a Splitter Bar
You can add both visual appeal and ease of use to a Visual Basic® application by including splitter bars. A splitter bar is a horizontal or vertical bar that the user clicks on to automatically resize a control, such as a Text Box, on a form. By using splitter bars, for instance, you can have two Text Boxes displayed on the application's window, one at the top of the form and the other at the bottom of the form. The splitter bar is positioned between the two text boxes. When the user drags the splitter bar (which is actually a Picture Box control) towards the top of the window, the first Text Box is made smaller and the second Text Box is made larger. Conversely, when the splitter bar is dragged towards the bottom of the window, the first Text Box grows in size vertically while the second Text Box shrinks in size vertically. This technique allows users to size the Text Box controls according to their own preferences, which also allows them to see more or less data in each individual control.

The key to creating a splitter bar in a Visual Basic application is the DragDrop event. Almost every control supports the DragDrop event. Each time a control is dropped at a new location, the DragDrop event is triggered. When the DragDrop event is triggered, the target control that you want to manipulate must contain the code to do whatever it is you want to do. In our example program below, we want to resize the text boxes, therefore we set the DragDrop event to trigger the Resize event for each Text Box on the form.

Each Text Box control is responsible for calling the Resize event of the program's main form, Form1. This Resize event causes Visual Basic to draw each Text Box control to its new size at its new position. This same technique can be applied to almost any other form or control except menus, timers, lines, and shapes.

Example Program
Create a new project in Visual Basic. Form1 is created by default. Set the following properties for Form1:
Height: 3735
Left: 1470
Top: 1320
Width: 6720

Add the following code to the Resize event for Form1:
Sub Form_Resize()
  Picture1.Left = 0
  'Make sure the form is not minimized!
  If Form1.ScaleHeight < Picture1.Height + 1 Then
      Form1.Height = Form1.Height - Form1.ScaleHeight + Picture1.Height + 1
      If Form1.ScaleHeight < Picture1.Top + Picture1.Height Then
          Picture1.Top = Form1.ScaleHeight - Picture1.Height - 1
  End If

  'Set Text1 to the Width and Height of form1
  Text1.Width = Form1.ScaleWidth
  Text1.Height = Form1.Picture1.Top

  Picture1.Width = Form1.ScaleWidth

  'Set Text2 to the Width and Height of Form1
  Text2.Top = Picture1.Top + Picture1.Height
  Text2.Width = Form1.ScaleWidth
  Text2.Height = Form1.ScaleHeight - Picture1.Top - Picture1.Height
  End If
End Sub

Add a Text Box control to Form1. Text1 is created by default. Set the following properties for Text1:
Height: 1815
Left: 0
Top: 0
Width: 6615

Add the following code to the DragDrop event for Text1:
Sub Text1_DragDrop(Source As Control, X As Single, Y As Single)
  If Y > 0 Then
      Picture1.Top = Y    'Move splitter bar.
  End If
End Sub

Add a second Text Box control to Form1. Text2 is created by default. Set the following properties for Text2:
Height: 1455
Left: 0
Top: 1920
Width: 6615

Add the following code to the DragDrop event for Text2:
Sub Text2_DragDrop(Source As Control, X As Single, Y As Single)
  If Y < Text2.Height Then
      Picture1.Top = Y + Text2.Top - Picture1.Height
  End If
End Sub

Add a Picture Box control to Form1. Picture1 is created by default. Set the following properties for Picture1:
BackColor: &H000000C0 (the color red)
DragMode: 1 (automatic)
DrawStyle: 0 (solid)
Height: 135
Left: 0
MousePointer: 7 (size n s)
Top: 1800
Width: 6495

Run the example program. A red bar (that is, the Picture Box control) separates the top Text Box from the bottom Text Box. You can resize either Text Box by clicking on the red bar and dragging the bar towards the top or bottom of Form1. When you release the mouse button, both Text Boxes are resized accordingly.

Author Comment

ID: 9813466
Thanks.  That gives me some ideas...

Expert Comment

ID: 9814918
A quick way to learn how to create and code a splitter bar is to use the application wizard and create an application using the explorer as the application type. It does all the coding for you and you can us this as a starting point

LVL 16

Expert Comment

ID: 9817587
not a bad idea.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question