CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Make my form Scrollable

    Is it possible to make your main form scrollable ? I want to insert a scrollbar on my form, but I can't figure out how to scroll.. I thought that a scrollbar would appear if you maximized your form and the form is too big for the window.. Doesn'T seem to act this way. I've been searching on this forum for this and it seems that it is not possible to do ?

    I'm suspicious about this. Anyone can help me out ?
    Nicolas Bohemier

  2. #2
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766
    On one of my screens, I have made it scrollable where the user reduces the size of the form below what it should be. This is how I did it.

    I put a picture box on the form, and put all the controls within the picture box. I then put scroll bars outside the picture box ie to the right and below.

    If the user reduces the screen below my threshold, then I enable the scroll bars eg:

    Code:
        If Me.Width < picScreen.Width Then
            hsbScrollBar.Visible = True
            hsbScrollBar.Width = Me.Width - (vsbScrollBar.Width + 100)
            hsbScrollBar.Max = (picScreen.Width - Me.Width) + vsbScrollBar.Width
            hsbScrollBar.Top = Me.Height - hScrollbarPos
            hsbScrollBar.Enabled = True
        Else
            hsbScrollBar.Enabled = False
            hsbScrollBar.Visible = False
        End If
    
        If Me.Height < picScreen.Height Then
            vsbScrollBar.Left = Me.Width - vScrollbarPos
            vsbScrollBar.Max = (picScreen.Height - Me.Height) + hsbScrollBar.Height
            vsbScrollBar.Height = Me.Height - (hsbScrollBar.Height + 100)
            vsbScrollBar.Visible = True
            vsbScrollBar.Enabled = True
            hsbScrollBar.Top = Me.Height - hScrollbarPos
        Else
            vsbScrollBar.Enabled = False
            vsbScrollBar.Visible = False
        End If
    The scroll bars then have the following code:

    Code:
    Private Sub vsbScrollBar_Change()
    
        Dim nPos As Integer
        
        nPos = Me.Height - vsbScrollBar
        nPos = Me.Height - nPos
    
        picScreen.Top = nPos * -1
        
    End Sub
    
    Private Sub hsbScrollBar_Change()
    
        Dim nPos As Integer
        
        nPos = Me.Width - hsbScrollBar
        nPos = Me.Width - nPos
        
        picScreen.Left = nPos * -1
        
    End Sub
    picScreen is the name of the picture box.

    Does this help?
    JP

    Please remember to rate all postings.

  3. #3
    Join Date
    Sep 2001
    Posts
    254

    scrollbars

    I've used ur sample codes its wonderful, only can u expand it to, when I click the arrows (up or down) the display scroll very slowy how i can change the speed of scrolling.

    thanks

  4. #4
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766
    Sorry, forgot to mention the values that you set for the properties of the scroll bars.

    I have set the small change property to 50, and the large value to 100.

    This will effect how often the change event is fired I believe - its a long time since I put this code in.

    Try changing the small and large change properties and see if this works for you.
    JP

    Please remember to rate all postings.

  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210
    I found a article in ELementKJournals that shows that the Form has its own scrollbars. It is relatively simple and you can scroll the form without the use of Pictureboxes. The only restriction is that controls without hwnds will disappear when scrolled off the viewport. To circumvent this put them, or everything in a picturebox,
    Check out the attached .ZIP file
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173
    Using the EventVB.dll release H is is fairly simple to make a form scrollable:

    Code:
    Option Explicit
    
    Dim WithEvents vbLink As EventVB.APIFunctions
    Dim WithEvents vbWnd As EventVB.ApiWindow
    
    Private Sub Form_Load()
    
    Set vbLink = New APIFunctions
    
    Set vbWnd = New ApiWindow
    
    With vbWnd
        .hWnd = Me.hWnd
        .ScrollBars = vbBoth
        .AutoScroll = True
    End With
    
    vbLink.SubclassedWindows.Add vbWnd
    
    End Sub
    Set the form's ClipControls member to false for best effect.

    HTH,
    Duncan
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  7. #7
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173
    Further to the above - the DLL is an ActiveX dll so you need to add it to your project references before you can use it.

    To do this select the menu Project :: References
    In ther resulting dialog box press "Browse"
    Find the file EventVB_H.dll and double clikc it.

    Then in your references list it will appear as:
    [x] MCL EventVB Release H
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  8. #8
    Join Date
    Mar 2004
    Posts
    11

    cannot find the dll

    I could not locate the EventVB_H.dll....can u please help

  9. #9
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210
    The EventVB_H.dll appears to be a >NET addition. It is not on my system either. For VB6, download my sample program and enjoy.

  10. #10
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Make my form Scrollable

    The EventVB_H.dll is wrtitten in VB6.0 - and the code for ther most recent version is attached to this thread

    (I would put it here as well, but at 215kb it is too big - the limit is 100k)
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured