Results 1 to 5 of 5

Thread: Scrolled Forms

  1. #1

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349

    Scrolled Forms

    Hi,
    I want to use a scrollable form - Can anyone point me in the direction of where to get info on how to do this?
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  2. #2
    hellswraith
    Guest
    Put a scroll bar on the form, then write the code in the scroll event. The code should reposition your controls based on what the scroll bar value is.

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    You can do thiw with the ApiWindow class of the EventVB.dll thus:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.APIFunctions
    4. Dim WithEvents vbWnd As EventVB.ApiWindow
    5.  
    6. Private Sub Form_Load()
    7.  
    8. Set vbLink = New APIFunctions
    9.  
    10. Set vbWnd = New ApiWindow
    11. With vbWnd
    12.     .hWnd = Me.hWnd
    13.     .ScrollBars = vbBoth
    14.     .AutoScroll = True
    15. End With
    16.  
    17. vbLink.SubclassedWindows.Add vbWnd
    18.  
    19. End Sub

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Scrollable Form

    VB Code:
    1. 'Add A Horizontal Scroll bar to the bottom of the screen, and a Vertical Scoll bar
    2. on the right hand edge.   Add A Picture Control with its border style set to 0
    3.  
    4. Option Explicit
    5.  
    6. Private iFullFormHeigth As Integer
    7. Private iFullFormWidth As Integer
    8. Private oldvPos As Integer
    9. Private oldhPos As Integer
    10.  
    11. Private Sub GetFullSize()
    12. Dim MyControl As Control
    13. Dim FullHtemp As Integer
    14. Dim FullVtemp As Integer
    15.  
    16. FullHtemp = 0
    17. FullVtemp = 0
    18. For Each MyControl In Me.Controls
    19.    If MyControl.Top + MyControl.Height > FullVtemp Then FullVtemp = MyControl.Top + MyControl.Height
    20.   If MyControl.Left + MyControl.Width > FullHtemp Then FullHtemp = MyControl.Left + MyControl.Width
    21. Next
    22. iFullFormHeigth = FullVtemp + HScroll1.Height
    23. iFullFormWidth = FullHtemp + VScroll1.Width
    24. End Sub
    25.  
    26. Private Sub ScrollMe()
    27. Dim MyControl As Control
    28. 'Moves each textbox and Control if the scrollbar is clicked
    29. For Each MyControl In Me.Controls
    30.     If Not (TypeOf MyControl Is VScrollBar) And _
    31.         Not (TypeOf MyControl Is PictureBox) And _
    32.         Not (TypeOf MyControl Is HScrollBar) Then
    33.         MyControl.Top = MyControl.Top + oldvPos - VScroll1.Value
    34.         MyControl.Left = MyControl.Left + oldhPos - HScroll1.Value
    35.     End If
    36. Next
    37. oldvPos = VScroll1.Value
    38. oldhPos = HScroll1.Value
    39. End Sub
    40.  
    41. Private Sub Form_Resize()
    42. VScroll1.Left = Me.Width - (1.45 * VScroll1.Width)
    43. HScroll1.Top = Me.Height - (2.45 * HScroll1.Height)
    44.  
    45. Picture1.Left = VScroll1.Left
    46. Picture1.Top = HScroll1.Top
    47.  
    48. 'If the full screen is already showing,
    49. 'then disable the scrollbar
    50. VScroll1.Enabled = (iFullFormHeigth - Me.Height) >= 0
    51.  
    52. 'First, make sure we aren't minimized
    53. If Me.ScaleHeight > HScroll1.Height And Me.Width > VScroll1.Width Then
    54.    
    55.     'If there is any more screen to see,
    56.     'modify the scrollbar
    57.     If VScroll1.Enabled Then
    58.         With VScroll1
    59.             .Height = Me.ScaleHeight - HScroll1.Height
    60.             .Min = 0
    61.             .Max = iFullFormHeigth - Me.Height
    62.             .SmallChange = Screen.TwipsPerPixelY * 10
    63.             .LargeChange = Me.ScaleHeight - HScroll1.Height
    64.         End With
    65.  
    66.     'Otherwise, just resize the scrollbar for neatness
    67.     Else
    68.             VScroll1.Height = Me.ScaleHeight - HScroll1.Height
    69.     End If
    70.  
    71.     HScroll1.Enabled = (iFullFormWidth - Me.Width) >= 0
    72.     If HScroll1.Enabled Then
    73.         With HScroll1
    74.             .Width = Me.ScaleWidth - VScroll1.Width
    75.             .Min = 0
    76.             .Max = iFullFormWidth - Me.Width
    77.             .SmallChange = Screen.TwipsPerPixelX * 10
    78.             .LargeChange = Me.ScaleWidth - VScroll1.Width
    79.         End With
    80.  
    81.     Else
    82.         HScroll1.Width = Me.ScaleWidth - VScroll1.Width
    83.     End If
    84. End If
    85. End Sub
    86.  
    87. Private Sub Form_Load()
    88. GetFullSize
    89. Form_Resize
    90. End Sub
    91.  
    92. Private Sub HScroll1_Change()
    93.     Call ScrollMe
    94. End Sub
    95.  
    96. Private Sub HScroll1_Scroll()
    97.     Call ScrollMe
    98. End Sub
    99.  
    100. Private Sub VScroll1_Change()
    101.     Call ScrollMe
    102. End Sub
    103.  
    104. Private Sub VScroll1_Scroll()
    105.     Call ScrollMe
    106. End Sub

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    This doesn't scroll any picture controls or scrollbars on your form, so you need to change

    VB Code:
    1. If Not (TypeOf MyControl Is VScrollBar) And _
    2.         Not (TypeOf MyControl Is PictureBox) And _
    3.         Not (TypeOf MyControl Is HScrollBar) Then

    To
    VB Code:
    1. If Not (MyControl.hwnd =  VScroll1.hwnd) And _
    2.         Not (MyControl.hwnd = Picture1.hwnd) And _
    3.         Not (MyControl.hwnd = HScroll1.hwnd) Then

    but i still reckon using subclassing to handle the WM_VSCROLL and WM_HSCROLL messages and setting the window styles WS_HSCROLL and WS_VSCROLL as above is a bit neater...

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

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