• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Scrollbars on a form

is there any way of adding scrollbars to my form so that the user can scroll across it at run time? The form is full screen size but I want the user only to see a small part of it but be able to move around it.
0
mi5
Asked:
mi5
1 Solution
 
mcriderCommented:
I just answered another question from someone else on this... Here is the answer they accepted:


You can always put all of your controls on a picturebox... then to "scroll" all you have to do if change the Top and Left properties of the picturebox...  You can do this with the HScroll and VScroll objects...


Here's an example:

1) Create a new project

2) Add a PictureBox object called "ScrollArea" to the form and set the Index property to 0.

3) Add a VScroll and a Hscroll object to the form.

4) Put some other controls on the PictureBox... It doesn't matter what, just so you can see the scroll work...

5) Add the following code to the DECLARATIONS SECTION of Form1 and run the program:

'-------------------------------------------------------------------------------
    Private Sub Form_Load()
        With ScrollArea(0)
            .Top = 0
            .Left = 0
        End With
        VScroll1.Top = 0
        HScroll1.Left = 0
        VScroll1.SmallChange = 100
        HScroll1.SmallChange = 100
        Load ScrollArea(1)
        With ScrollArea(1)
            .Width = VScroll1.Width
            .Height = HScroll1.Height
            .ZOrder
            .Visible = True
            .BackColor = &H80000016
            .BorderStyle = 1
        End With
    End Sub
    Private Sub Form_Resize()
        Dim VisibleWidth As Long
        Dim VisibleHeight As Long
        VisibleWidth = Me.Width - VScroll1.Width - 120
        VisibleHeight = Me.Height - HScroll1.Height - 420
        VScroll1.LargeChange = VisibleHeight
        HScroll1.LargeChange = VisibleWidth
        VScroll1.Height = VisibleHeight
        HScroll1.Width = VisibleWidth
        VScroll1.Left = VisibleWidth
        HScroll1.Top = VisibleHeight
        ScrollArea(1).Top = VisibleHeight
        ScrollArea(1).Left = VisibleWidth
        If ScrollArea(0).Width > VisibleWidth Then
            HScroll1.Max = Abs(ScrollArea(0).Width - VisibleWidth)
        Else
            HScroll1.Max = 0
        End If
        If ScrollArea(0).Height > VisibleHeight Then
            VScroll1.Max = Abs(ScrollArea(0).Height - VisibleHeight)
        Else
            VScroll1.Max = 0
        End If
    End Sub
    Private Sub HScroll1_Change()
        ScrollArea(0).Left = 0 - HScroll1.Value
    End Sub
    Private Sub HScroll1_GotFocus()
        ScrollArea(0).SetFocus
    End Sub
    Private Sub HScroll1_Scroll()
        HScroll1_Change
        DoEvents
    End Sub
    Private Sub VScroll1_Change()
        ScrollArea(0).Top = 0 - VScroll1.Value
    End Sub
    Private Sub VScroll1_GotFocus()
        ScrollArea(0).SetFocus
    End Sub
    Private Sub VScroll1_Scroll()
        VScroll1_Change
        DoEvents
    End Sub
'-------------------------------------------------------------------------------

6) While the program is running, resize the form and then use the scrollbars...


Cheers!®©

0
 
BobbyOwensCommented:
There is an API call to show the scroll bars, but you'll need to code to use them.

The only time I've done something similar is when I added 2 scroll bar controls and had all my other controls on a picture box. As I scrolled, I moved the picture box.

Make sure the form isn't sizable.
0
 
AzraSoundCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
VbmasterCommented:
In case the program is not only for your use I would recommend you to use API's to create and subclass real win32 scrollbars, and not VB's ugly ones. You can find code to implement these scrollbars at...

http://www.vbaccelerator.com/codelib/ssubtmr/sbrclass.htm

There is even a example project there showing how to do a form with scrollbars the way you want it.
0
 
mcriderCommented:
Vbmaster, what do you mean ugly?? They look identical...
0
 
mcriderCommented:
Vbmaster, this is a quote from the site you gave:

"they don't draw in the neat,professional style of Win32 scroll bars (the worst offense is the continual flashing when in focus and the fact it is impossible to prevent this occuring!)"

I suggest you try the example I posted... This flashing does not occur. ;-)


Cheers!®©
0
 
VbmasterCommented:
Oh yea you're right that code in the GotFocus() events of your's fixes the flashing, it was the flashing that bothered me the most with the standard VB scrollbars. mi5, ignore my old comment, using the standard VB scrollbars is probably the best solution here. ;)
0
 
mcriderCommented:
Vbmaster, the other thing about my scrollbar example is that it smooth scrolls as you drag the scrollbar up and down... ;-)
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!®©
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now