Solved

How to move frames on a form with a sliding control

Posted on 2003-11-24
5
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 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