?
Solved

Scrollbars on a form

Posted on 2000-05-10
9
Medium Priority
?
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 150 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

801 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