Solved

How to move frames on a form with a sliding control

Posted on 2003-11-24
5
513 Views
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?
0
Comment
Question by:Ficus
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9813163
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 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

Abstract
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
  Else
      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.
      Form_Resize
  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
      Form_Resize
  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.
0
 
LVL 3

Author Comment

by:Ficus
ID: 9813466
Thanks.  That gives me some ideas...
0
 
LVL 4

Expert Comment

by:SSSoftware
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


Ed
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9817587
not a bad idea.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now