Solved

How to create a scrollable form

Posted on 2002-03-04
3
249 Views
Last Modified: 2010-05-02
I have a form in which I need to place a lot objects, "mostly text boxes", how can I make the form scrollable so that all objects can fit on one form?
0
Comment
Question by:Draner
[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
3 Comments
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 90 total points
ID: 6840426
Some of the application use Picturebox + Scrollbar to do this tricks:

http://www.freevbcode.com/ShowCode.ASP?SearchString=scrollable%20form&ID=1549

0
 

Author Comment

by:Draner
ID: 6840618
Good example, thanks
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6840630
Copy this code into a new Notepad document and save it as frmScroll.frm. Then open it in VB:

VERSION 5.00
Begin VB.Form frmScroll
   Caption         =   "Scrollable form in VB"
   ClientHeight    =   3045
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6255
   LinkTopic       =   "Form1"
   ScaleHeight     =   3045
   ScaleWidth      =   6255
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdStay
      Caption         =   "Stay In Place"
      Height          =   495
      Left            =   4440
      TabIndex        =   16
      Top             =   120
      Width           =   1215
   End
   Begin VB.VScrollBar VScroll1
      Height          =   3015
      LargeChange     =   100
      Left            =   5760
      Max             =   3000
      TabIndex        =   15
      Top             =   0
      Width           =   495
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   495
      Left            =   2400
      TabIndex        =   14
      Top             =   5520
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   6
      Left            =   1440
      TabIndex        =   13
      Text            =   "7"
      Top             =   4560
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   5
      Left            =   1440
      TabIndex        =   11
      Text            =   "6"
      Top             =   3840
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   4
      Left            =   1440
      TabIndex        =   9
      Text            =   "5"
      Top             =   3120
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   3
      Left            =   1440
      TabIndex        =   7
      Text            =   "4"
      Top             =   2400
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   2
      Left            =   1440
      TabIndex        =   5
      Text            =   "3"
      Top             =   1680
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   1
      Left            =   1440
      TabIndex        =   3
      Text            =   "2"
      Top             =   960
      Width           =   1215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   0
      Left            =   1440
      TabIndex        =   1
      Text            =   "1"
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label7"
      Height          =   495
      Index           =   6
      Left            =   120
      TabIndex        =   12
      Top             =   4560
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label6"
      Height          =   495
      Index           =   5
      Left            =   120
      TabIndex        =   10
      Top             =   3840
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label5"
      Height          =   495
      Index           =   4
      Left            =   120
      TabIndex        =   8
      Top             =   3120
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label4"
      Height          =   495
      Index           =   3
      Left            =   120
      TabIndex        =   6
      Top             =   2400
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label3"
      Height          =   495
      Index           =   2
      Left            =   120
      TabIndex        =   4
      Top             =   1680
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label2"
      Height          =   495
      Index           =   1
      Left            =   120
      TabIndex        =   2
      Top             =   960
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Label1"
      Height          =   495
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "frmScroll"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Explanation:
'   1. Start out by making the form big enough to show
'      all the controls of the form.
'   2. Make a note of the height of the form.
'   3. Resize the form to the display size.
'   4. Make a note of the height of the form.
'   5. Place a vertical scroll bar control on the right side of the form.
'   6. The Max property of the scroll bar should be set to the difference
'      between the height of the full form (2) less the height of the
'      displayed form (4).

Private OldScrollPos As Integer

Private Sub VScroll1_Change()
    ScrollControls
End Sub

Private Sub VScroll1_Scroll()
    ScrollControls
End Sub

Private Sub ScrollControls()
Dim ctl As Control

    For Each ctl In Me.Controls
        'Check for controls that don't move
        If TypeOf ctl Is VScrollBar Or _
           ctl.Name = "cmdStay" _
        Then
            'do nothing
        Else
            ctl.Top = ctl.Top + OldScrollPos - VScroll1.Value
        End If
    Next
    OldScrollPos = VScroll1.Value
End Sub
0

Featured Post

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.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 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 Month6 days, 1 hour left to enroll

627 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