Solved

Scrollbars on a form(VB6)

Posted on 2002-07-02
6
2,341 Views
Last Modified: 2011-10-03
How do I put working scrollbars on a form. I dynamically create some controls and there is no other way than to pass the size of the form. Yet I am unabler to add working scrollbars to it.
0
Comment
Question by:MsShadow
6 Comments
 
LVL 3

Accepted Solution

by:
SirNick earned 50 total points
ID: 7124734
Hello MsShadow

Have a look at the following link.

http://www.freevbcode.com/ShowCode.Asp?ID=1230

Hope this helps...
0
 
LVL 3

Expert Comment

by:schworak
ID: 7124780
There is a really simple trick to this....


Create a PICTURE BOX the size of your form when it is at it's maximum size. Place all your controls inside this picture box (no border is needed on the picture box by the way)

Place your scroll bars on the form (not the picture box) Then you can use the value of the scrollers to move the picture box and all the controlls will move properly.

Realize this is a quick and dirty example and you will need to tweek on it to get the exact effect you are after.

Paste the code below into a file named PicBox.frm (or what ever) and see how this works...


VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   7620
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   10350
   LinkTopic       =   "Form1"
   ScaleHeight     =   7620
   ScaleWidth      =   10350
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2
      Height          =   255
      Left            =   6780
      TabIndex        =   8
      Top             =   6900
      Width           =   255
   End
   Begin VB.HScrollBar HScroll1
      Height          =   255
      Left            =   300
      TabIndex        =   7
      Top             =   6840
      Width           =   5535
   End
   Begin VB.VScrollBar VScroll1
      Height          =   6435
      Left            =   9240
      TabIndex        =   6
      Top             =   120
      Width           =   255
   End
   Begin VB.PictureBox PB
      BorderStyle     =   0  'None
      Height          =   6075
      Left            =   300
      ScaleHeight     =   6075
      ScaleWidth      =   8475
      TabIndex        =   0
      Top             =   360
      Width           =   8475
      Begin VB.FileListBox File1
         Height          =   3405
         Left            =   360
         TabIndex        =   5
         Top             =   2460
         Width           =   3195
      End
      Begin VB.ListBox List1
         Height          =   3375
         ItemData        =   "Form1.frx":0000
         Left            =   3900
         List            =   "Form1.frx":0016
         TabIndex        =   4
         Top             =   2340
         Width           =   2955
      End
      Begin VB.ComboBox Combo1
         Height          =   315
         Left            =   900
         TabIndex        =   3
         Text            =   "Combo1"
         Top             =   1620
         Width           =   1695
      End
      Begin VB.TextBox Text1
         Height          =   315
         Left            =   2280
         TabIndex        =   2
         Text            =   "Text1"
         Top             =   780
         Width           =   2595
      End
      Begin VB.CommandButton Command1
         Caption         =   "Command1"
         Height          =   675
         Left            =   240
         TabIndex        =   1
         Top             =   120
         Width           =   1455
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command2_Click()
    VScroll1.Value = 0
    HScroll1.Value = 0
End Sub

Private Sub Form_Load()
    HScroll1.SmallChange = Screen.TwipsPerPixelY
    HScroll1.LargeChange = HScroll1.SmallChange * 25
    VScroll1.SmallChange = Screen.TwipsPerPixelX
    VScroll1.LargeChange = VScroll1.SmallChange * 25
    PB.Move 0, 0
    PB.ZOrder 1
End Sub

Private Sub Form_Resize()
    VScroll1.Value = 0
    VScroll1.Move Me.ScaleWidth - VScroll1.Width, 0, VScroll1.Width, Me.ScaleHeight - HScroll1.Height
    VScroll1.Visible = (Me.ScaleHeight < PB.Height)
    VScroll1.Max = Me.ScaleHeight - PB.Height
    HScroll1.Value = 0
    HScroll1.Move 0, Me.ScaleHeight - HScroll1.Height, Me.ScaleWidth - VScroll1.Width, HScroll1.Height
    HScroll1.Visible = (Me.ScaleWidth < PB.Width)
    HScroll1.Max = Me.ScaleWidth - PB.Width
    Command2.Move VScroll1.Left, HScroll1.Top, VScroll1.Width, HScroll1.Height
    Command2.Visible = (VScroll1.Visible Or HScroll1.Visible)
End Sub

Private Sub HScroll1_Change()
    If HScroll1.Visible Then
        PB.Left = HScroll1.Value
    Else
        PB.Left = 0
    End If
End Sub

Private Sub HScroll1_Scroll()
    HScroll1_Change
End Sub

Private Sub VScroll1_Change()
    If VScroll1.Visible Then
        PB.Top = VScroll1.Value
    Else
        PB.Top = 0
    End If
End Sub

Private Sub VScroll1_Scroll()
    VScroll1_Change
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7125825
Redesign your app.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 19

Author Comment

by:MsShadow
ID: 7126082
The design has been requested by the client, no way around it.
0
 
LVL 19

Author Comment

by:MsShadow
ID: 7126253
Thanks, worked perfectly.
0
 
LVL 3

Expert Comment

by:SirNick
ID: 7127289
Thanks for the points...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

15 Experts available now in Live!

Get 1:1 Help Now