Solved

Scrollbars on a form(VB6)

Posted on 2002-07-02
6
2,342 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 64
Excel - Save a copy of work book 13 83
Spell Check in VB6 13 96
how to know if my Checkbox is True in VB6.0? 9 38
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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 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

23 Experts available now in Live!

Get 1:1 Help Now