home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Arranging Scrolling Area Controls

When Scroller creates the scrolling area controls, it gives the package control a Resize event handler. When this control is resized, the event handler calls the ArrangeScrollingArea subroutine, as shown in the following code.

Private Sub Picture3_Resize()
    ‘ Call ArrangeScrollingArea to
    ‘ set scroll bar parameters.
    ArrangeScrollingArea _
        Picture3, _
        Picture2, _
        HScroll1, _
        VScroll1, _
        Picture1
End Sub

The code placed in this event handler refers to the actual control names as they are created by Visual Basic. For example, if Visual Basic named the package control Picture7 instead of Picture3, this subroutine would be named Picture7_Resize and it would use Picture7 as the first parameter to the ArrangeScrollingArea subroutine.

ArrangeScrollingArea, contained in module Scroller.BAS, places the scrolling area controls and sets the scroll bars’ parameters. It determines which scroll bars are necessary and hides any that are not.

Sub ArrangeScrollingArea(package As PictureBox, _
    viewport As PictureBox, hscroll As HScrollBar, _
    vscroll As VScrollBar, scroll_area As PictureBox)
Dim viewport_xgap As Single
Dim viewport_ygap As Single
Dim need_wid As Single
Dim need_hgt As Single
Dim got_wid As Single
Dim got_hgt As Single
Dim need_hscroll As Boolean
Dim need_vscroll As Boolean

    ‘ See how big things are.
    viewport_xgap = viewport.Width - viewport.ScaleWidth
    viewport_ygap = viewport.Height - viewport.ScaleHeight
    got_wid = package.ScaleWidth - viewport_xgap
    got_hgt = package.ScaleHeight - viewport_ygap
    need_wid = scroll_area.Width
    need_hgt = scroll_area.Height
    
    ‘ See which scroll bars we need.
    If need_wid > got_wid Then
        need_hscroll = True
        got_hgt = got_hgt - hscroll.Height
    End If
    If need_hgt > got_hgt Then
        need_vscroll = True
        got_wid = got_wid - vscroll.Width
        If Not need_hscroll Then
            If need_wid > got_wid Then
                need_hscroll = True
                got_hgt = got_hgt - hscroll.Height
            End If
        End If
    End If
    
    ‘ Make sure we don’t make things too small.
    got_wid = got_wid + viewport_xgap
    got_hgt = got_hgt + viewport_ygap
    If got_wid < vscroll.Width Then _
       got_wid = vscroll.Width
    If got_hgt < hscroll.Height Then _
       got_hgt = hscroll.Height
    
    ‘ Rearrange the controls.
    viewport.Move 0, 0, got_wid, got_hgt
    If need_hscroll Then _
        hscroll.Move 0, got_hgt, got_wid
    hscroll.Visible = need_hscroll
    If need_vscroll Then _
        vscroll.Move got_wid, 0, vscroll.Width, got_hgt
    vscroll.Visible = need_vscroll
    scroll_area.Move 0, 0

    ‘ Set the scroll bar parameters.
    If need_hscroll Then
        hscroll.Min = 0
        hscroll.Max = scroll_area.Width - viewport.ScaleWidth
        hscroll.SmallChange = 0.1 * viewport.ScaleWidth
        hscroll.LargeChange = 0.9 * viewport.ScaleWidth
    End If
    If need_vscroll Then
        vscroll.Min = 0
        vscroll.Max = scroll_area.Height - viewport.ScaleHeight
        vscroll.SmallChange = 0.1 * viewport.ScaleHeight
        vscroll.LargeChange = 0.9 * viewport.ScaleHeight
    End If
End Sub

Summary

The PropertySetter and Aligner add-ins described in Chapters 4 and 5 modify the properties of controls that already exist in a project. Scroller adds completely new controls and new source code to a project. It uses the code and controls to automatically build scrolling regions.

Using similar techniques an add-in could add other more complex combinations of new controls and source code to a project. The AddInMaker add-in described in Chapter 7, for example, creates new source code to make implementing other add-ins easy.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.