Results 1 to 5 of 5

Thread: Scrolling controls

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Westminster, Md.
    Posts
    163
    I've been trying to find some reference to this here, but nothing has popped up so far. Surely someone has tried this before.

    I'd like to be able to scroll the contents of a form (or frame on a form) up or down so that more data can be displayed. By using a scroll bar to change the position of the objects just like in a word processor or browser document.

    I realize it's as simple as just using the .move method on the objects but for some reason I can't seem to get the Vscroll control to come up with anything remotely resembling what a word processor or browser's scrollbar does.

    Anyone have any advise on this? I figure it's gotta be in here already some where...

    Thanks,
    Eiredrake

  2. #2
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    I've never done this myself, but I hear that a Picturebox is scrollable, so you can embed all the objects on your form onto the picturebox, and scroll that.
    Courgettes.

  3. #3
    Guest
    picture boxes are wasteful of memory.

    try this, put a frame on the form, and inside that, put another frame and a scrollbar. put all your controls indside this second frame. write some code in the scrollbar event to make the second frame move abour inside the first frame, effectively moving all the controls too. you will have to make the second frame's border invisible though or it will look goofy.

  4. #4
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Wink

    A PictureBox won't do any damage to the 256MB of RAM monsters we have in the world today.

    (Brain: That's a petty excuse)
    (Imagination: You think of a better one.)
    (Brain: Yeah, but I delegate all imaginative stuff to you.)
    (Imagination: Aha. You can keep your mouth shut then)
    (Brain: Make me)
    (Imagination: I make make you think about that time in India, when that man you went to see...)
    (Brain: No. Not that. Noooooooooo)

    My mind is like a sieve: It keeps in all that stuff that is lumpy and ugly.
    Courgettes.

  5. #5
    Guest
    Without using a PictureBox or Frame, you can loop through all of the controls in the Form and move them respectivley.
    Code:
    Dim VPos As Integer
    Dim HPos As Integer
    
    Private Sub Form_Load()
        'Change the following numbers to the Full height and width of your Form
        intFullHeight = 8000
        intFullWidth = 8000
        'This is the how much of your Form is displayed
        intDisplayHeight = Me.Height
        intDisplayWidth = Me.Width
    
        With VScroll1
            .Height = Me.ScaleHeight
            .Min = 0
            .Max = intFullHeight - intDisplayHeight
            .SmallChange = Screen.TwipsPerPixelX * 10
            .LargeChange = .SmallChange
        End With
        With HScroll1
            .Width = Me.ScaleWidth
            .Min = 0
            .Max = intFullWidth - intDisplayWidth
            .SmallChange = Screen.TwipsPerPixelX * 10
            .LargeChange = .SmallChange
        End With
    End Sub
    
    Sub ScrollForm(Direction As Byte)
        Dim CTL As Control
        
        'Scroll Vertically
        If Direction = 0 Then
            For Each CTL In Me.Controls
                'Make sure it's not a ScrollBar
                If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
                    'If it's a Line then
                    If TypeOf CTL Is Line Then
                        CTL.Y1 = CTL.Y1 + VPos - VScroll1.Value
                        CTL.Y2 = CTL.Y2 + VPos - VScroll1.Value
                    Else
                        CTL.Top = CTL.Top + VPos - VScroll1.Value
                    End If
                End If
            Next
            VPos = VScroll1.Value
        Else
            'Scroll Horizontally
            For Each CTL In Me.Controls
                'Make sure it's not a ScrollBar
                If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
                    'If it's a Line then
                    If TypeOf CTL Is Line Then
                        CTL.X1 = CTL.X1 + HPos - HScroll1.Value
                        CTL.X2 = CTL.X2 + HPos - HScroll1.Value
                    Else
                        CTL.Left = CTL.Left + HPos - HScroll1.Value
                    End If
                End If
            Next
            HPos = HScroll1.Value
        End If
    End Sub
    
    Private Sub HScroll1_Change()
        ScrollForm 1
    End Sub
    
    Private Sub HScroll1_Scroll()
        ScrollForm 1
    End Sub
    
    Private Sub VScroll1_Change()
        ScrollForm 0
    End Sub
    
    Private Sub VScroll1_Scroll()
        ScrollForm 0
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width