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?
Printable View
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?
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.
You can do thiw with the ApiWindow class of the EventVB.dll thus:
VB 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
HTH,
Duncan
VB Code:
'Add A Horizontal Scroll bar to the bottom of the screen, and a Vertical Scoll bar on the right hand edge. Add A Picture Control with its border style set to 0 Option Explicit Private iFullFormHeigth As Integer Private iFullFormWidth As Integer Private oldvPos As Integer Private oldhPos As Integer Private Sub GetFullSize() Dim MyControl As Control Dim FullHtemp As Integer Dim FullVtemp As Integer FullHtemp = 0 FullVtemp = 0 For Each MyControl In Me.Controls If MyControl.Top + MyControl.Height > FullVtemp Then FullVtemp = MyControl.Top + MyControl.Height If MyControl.Left + MyControl.Width > FullHtemp Then FullHtemp = MyControl.Left + MyControl.Width Next iFullFormHeigth = FullVtemp + HScroll1.Height iFullFormWidth = FullHtemp + VScroll1.Width End Sub Private Sub ScrollMe() Dim MyControl As Control 'Moves each textbox and Control if the scrollbar is clicked For Each MyControl In Me.Controls If Not (TypeOf MyControl Is VScrollBar) And _ Not (TypeOf MyControl Is PictureBox) And _ Not (TypeOf MyControl Is HScrollBar) Then MyControl.Top = MyControl.Top + oldvPos - VScroll1.Value MyControl.Left = MyControl.Left + oldhPos - HScroll1.Value End If Next oldvPos = VScroll1.Value oldhPos = HScroll1.Value End Sub Private Sub Form_Resize() VScroll1.Left = Me.Width - (1.45 * VScroll1.Width) HScroll1.Top = Me.Height - (2.45 * HScroll1.Height) Picture1.Left = VScroll1.Left Picture1.Top = HScroll1.Top 'If the full screen is already showing, 'then disable the scrollbar VScroll1.Enabled = (iFullFormHeigth - Me.Height) >= 0 'First, make sure we aren't minimized If Me.ScaleHeight > HScroll1.Height And Me.Width > VScroll1.Width Then 'If there is any more screen to see, 'modify the scrollbar If VScroll1.Enabled Then With VScroll1 .Height = Me.ScaleHeight - HScroll1.Height .Min = 0 .Max = iFullFormHeigth - Me.Height .SmallChange = Screen.TwipsPerPixelY * 10 .LargeChange = Me.ScaleHeight - HScroll1.Height End With 'Otherwise, just resize the scrollbar for neatness Else VScroll1.Height = Me.ScaleHeight - HScroll1.Height End If HScroll1.Enabled = (iFullFormWidth - Me.Width) >= 0 If HScroll1.Enabled Then With HScroll1 .Width = Me.ScaleWidth - VScroll1.Width .Min = 0 .Max = iFullFormWidth - Me.Width .SmallChange = Screen.TwipsPerPixelX * 10 .LargeChange = Me.ScaleWidth - VScroll1.Width End With Else HScroll1.Width = Me.ScaleWidth - VScroll1.Width End If End If End Sub Private Sub Form_Load() GetFullSize Form_Resize End Sub Private Sub HScroll1_Change() Call ScrollMe End Sub Private Sub HScroll1_Scroll() Call ScrollMe End Sub Private Sub VScroll1_Change() Call ScrollMe End Sub Private Sub VScroll1_Scroll() Call ScrollMe End Sub
This doesn't scroll any picture controls or scrollbars on your form, so you need to change
VB Code:
If Not (TypeOf MyControl Is VScrollBar) And _ Not (TypeOf MyControl Is PictureBox) And _ Not (TypeOf MyControl Is HScrollBar) Then
To
VB Code:
If Not (MyControl.hwnd = VScroll1.hwnd) And _ Not (MyControl.hwnd = Picture1.hwnd) And _ 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