Solved

Scrollbars on a form

Posted on 2000-05-10
9
380 Views
Last Modified: 2010-05-02
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
Comment
Question by:mi5
9 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 50 total points
ID: 2796224
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
 
LVL 2

Expert Comment

by:BobbyOwens
ID: 2796284
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2796310
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2796361
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 14

Expert Comment

by:mcrider
ID: 2796471
Vbmaster, what do you mean ugly?? They look identical...
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2796483
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
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2796561
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2796597
Vbmaster, the other thing about my scrollbar example is that it smooth scrolls as you drag the scrollbar up and down... ;-)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2800231
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now