Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Nested scrollable frames/forms

views
     
TSAthono
post Mar 10 2006, 11:13 AM, updated 19y ago

Getting Started
**
Junior Member
227 posts

Joined: Dec 2005
I want to have a nested scrollable area (with buttons and controls) inside a dialog. Is this easy to do in Visual Basic?
TSAthono
post Mar 12 2006, 08:03 AM

Getting Started
**
Junior Member
227 posts

Joined: Dec 2005
I found the following sample code:

CODE
Option Explicit

' Arrange the scroll bars.
Private Sub ArrangeScrollBars()
Dim have_wid As Single
Dim have_hgt As Single
Dim need_wid As Single
Dim need_hgt As Single
Dim need_hbar As Boolean
Dim need_vbar As Boolean

   ' Don't bother if we're minimized.
   If WindowState = vbMinimized Then Exit Sub

   ' See how much room we need and
   ' how much room we have.
   need_wid = picInner.Width + (picOuter.Width - picOuter.ScaleWidth)
   need_hgt = picInner.Height + (picOuter.Height - picOuter.ScaleHeight)
   have_wid = ScaleWidth
   have_hgt = ScaleHeight

   ' See which scroll bars we need.
   need_hbar = (need_wid > have_wid)
   If need_hbar Then have_hgt = have_hgt - HBar.Height

   need_vbar = (need_hgt > have_hgt)
   If need_vbar Then
       ' This takes away a little width so we
       ' might need the horizontal scroll bar now.
       have_wid = have_wid - VBar.Width
       If Not need_hbar Then
           need_hbar = (need_wid > have_wid)
           If need_hbar Then have_hgt = have_hgt - HBar.Height
       End If
   End If

   ' Position the outer PictureBox leaving room
   ' for the scroll bars.
   picOuter.Move 0, 0, have_wid, have_hgt

   ' Position or hide the scroll bars.
   If need_hbar Then
       HBar.Move 0, have_hgt, have_wid
       HBar.Min = 0
       HBar.Max = picOuter.ScaleWidth - picInner.Width
       HBar.LargeChange = picOuter.ScaleWidth
       HBar.SmallChange = picOuter.ScaleWidth / 5
       HBar.Visible = True
   Else
       HBar.Visible = False
   End If

   If need_vbar Then
       VBar.Move have_wid, 0, VBar.Width, have_hgt
       VBar.Min = 0
       VBar.Max = picOuter.ScaleHeight - picInner.Height
       VBar.LargeChange = picOuter.ScaleHeight
       VBar.SmallChange = picOuter.ScaleHeight / 5
       VBar.Visible = True
   Else
       VBar.Visible = False
   End If
End Sub
Private Sub Form_Resize()
   ArrangeScrollBars
End Sub
Private Sub HBar_Change()
   picInner.Left = HBar.Value
End Sub


Private Sub HBar_Scroll()
   picInner.Left = HBar.Value
End Sub


Private Sub VBar_Change()
   picInner.Top = VBar.Value
End Sub


Private Sub VBar_Scroll()
   picInner.Top


Problem: Solved.

 

Change to:
| Lo-Fi Version
0.0112sec    0.34    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 01:27 PM