Link to home
Start Free TrialLog in
Avatar of lsmith2574
lsmith2574

asked on

Creating Scrollable MDI Child Forms

I am creating a Visual Basic 6 MDI application that is made up of numerous MDI child forms.  I would like for the child forms to have a vertical scroll bar that allows the user to scroll to view hard to see data.  I looked at the answer to question 10050026 from clsmaster and tried the code and it didn't work for me.  My vertical scroll bar kept shrinking to the top of my form.  In clsmaster's response there are several things that are unclear.  For instance, when he/she says set the tag property of the control to the top property on the control which control is he referring to?  Set the scroll bar control's tag property to the top property of the scroll bar or the form?  Also, there's no such thing as on local error resume next.  If someone could provide me with code that will allow me to add vertical and horizontal scroll bars to mdi child forms within a mdi environment to produce scrolling that is similiar to Microsoft Word, I would greatly appreciately.
Avatar of Ruchi
Ruchi

Ruchi... I dont see how that link helps - are you sure you got the URL right ?

To create scrollable forms I use the following technique :

Create a picture box to be the viewable area and call it picFrame and set it to the appropriate size (perhaps to cover the entire form). Then create another control inside this which will be the actual document itself (for this example I use a picture box called picCanvas).Set picCanvas's width and height properties to the actual size you want (not the visible area).

Add a vertical scrollbar and a horizontal scrollbar again into picFrame (not picCanvas). Then set the top and left properties of picCanvas to 0.

In picFrame_Resize event :

scrVertical.Left = picFrame.ScaleWidth - scrVertical.Width
    scrVertical.Height = picFrame.ScaleHeight - scrHorizontal.Height
    scrVertical.Max = picCanvas.Height - picFrame.ScaleHeight
   
    scrHorizontal.Width = picFrame.ScaleWidth - scrHorizontal.Left - scrVertical.Width
    scrHorizontal.Top = picFrame.ScaleHeight - scrHorizontal.Height
    scrHorizontal.Max = picCanvas.Width - picFrame.Width

Then in the vertical scrollbar Change event :

    picCanvas.Top = -scrVertical.Value
    picCanvas.SetFocus

And in the horizontal scrollbar :
    picCanvas.left= -scrHorizontal.Value
    picCanvas.SetFocus

Now when you move the scrollbars the viewable portion of picCanvas is panned. Not that a picture box can contain other controls, so picCanvas could have text boxes, labels etc placed on it.

Hope this helps.
Goto http://www.planet-source-code.com and check out the VB section.  In the VB section do a search on ScrollingForm.  You should find a custom control I posted there that might meet your needs.  The custom control allows you to automatically scroll objects on the form (that are placed within the control), and allows you to scroll during design time to place controls.  Hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lsmith2574

ASKER

AngelIII,
I would like to see the OCX that you have.  Just let me know where I can retrieve it from or what information you need from me.
My email is lsmith7@hotmail.com.