Solved

Vertical scrollbar with picturebox in VB3

Posted on 1999-01-04
9
445 Views
Last Modified: 2009-07-29
I have a picturebox which takes input from a variable length file (the picturebox height increases as the information is read in from the file, the width always remains the same).  I have to alter the vertical scrollbar after the picturebox is displayed so that all of the information in the picturebox can be viewed.  

The problem is it either scrolls too much past the end of the picturebox, doesn't scroll enough or gets an error because the value is too high.

This is what I have been using;

vscroll1.max = picture1.height - scaleheight
vscroll1.top = -vscroll1.value

plus I have been using many other variations for several hours and can't seem to get the desired results.
0
Comment
Question by:rround
  • 5
  • 2
  • 2
9 Comments
 

Author Comment

by:rround
ID: 1453840
Edited text of question
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 1453841
To scroll, here is an example that scrolls verticaly.
To allow better testing, it uses Shape control (it is easy to change size and visualize it). You can use PictureBox.

'Tested in VB5
'Start new project. Form1 is created by default.
'Add TextBox, Shape and VScrollBar to your form.
'Paste this code
Option Explicit

Private Sub Form_Click()
    Dim msg As String
    msg = msg & "" & vbCrLf & vbCrLf
    msg = msg & "Form height: " & Me.ScaleHeight & vbCrLf
    msg = msg & "Shape height " & Shape1.Height & _
                ", top " & Shape1.Top & vbCrLf
    msg = msg & "VScroll Min " & VScroll1.Min & _
                ", Max " & VScroll1.Max & _
                ", Val " & VScroll1.Value & _
                ", LargeChange " & VScroll1.LargeChange & vbCrLf
    Me.CurrentY = 0
    Print msg
End Sub

Private Sub Form_Load()
    ScaleMode = vbPixels ' 3
    Shape1.Shape = vbShapeOval '2
    VScroll1.Width = 17
    VScroll1.TabStop = False
    Text1.Move 28, 4, 41
    Text1.Text = "" 
End Sub

Private Sub Form_Resize()
    Caption = "Enter shape height, >" & Me.ScaleHeight
    VScroll1.Move ScaleWidth - VScroll1.Width, 0, VScroll1.Width, ScaleHeight
    Shape1.Move 0, 0, ScaleWidth - VScroll1.Width
    Adjust
End Sub

Private Sub Text1_Change()
    On Error GoTo hgerr
    Dim hg As Single
    hg = CSng(Text1.Text)
    Shape1.Top = 0
    Shape1.Height = hg ' new height
    Adjust
    Exit Sub
hgerr:
    Debug.Print Err.Description
    Exit Sub
End Sub

Private Sub VScroll1_Change()
    Pos
End Sub

Private Sub VScroll1_Scroll()
    Pos
End Sub

Sub Pos()
    Shape1.Top = -VScroll1.Value
End Sub

Sub Adjust()
    ' set 3 properties of vert scrollbar
    VScroll1.Value = 0
    If Shape1.Height < ScaleHeight Then ' no need to scroll
        VScroll1.Max = 0
    Else
        VScroll1.Max = Abs(ScaleHeight - Shape1.Height)
    End If
    VScroll1.LargeChange = ScaleHeight
End Sub
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1453842
VScroll1.Max is limited from -32,768 to 32,767, inclusive.

So you should fix the VScroll1.Min=0 , VScroll1.Max=32000 and compute the values of VScroll1.LargeChange, VScroll1.SmallChange and VScroll1.Value accordingly to your effective size.
0
 

Author Comment

by:rround
ID: 1453843
Ameba,

This still doesn't work.  I had already tried most of code in your suggestion but on the larger pictureboxes, it doesn't scroll far enough to reach some of the information, and on smaller pictureboxes, it scrolls too far.

Chabaud,

I think I must be missing something in calculating the effective size.  The Scaleheight is 7215 twips.  Now, If I have a picturebox and its final size is 41885, then I should have:
VScroll1.Max=picture1.height-scaleheight
Picture1.Top =-VScroll1.Value

right?  But using this, the bottom of the picturebox is missing.  When the final size is only 11985 then the scrollbar scrolls way past the bottom of the picturebox.  The problem is, each time my app runs, the size of the picturebox will vary.  What am I missing to make this work?
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 15

Expert Comment

by:ameba
ID: 1453844
Why don't you use
    ScaleMode = vbPixels ' 3
Your form scaleheight will be  7215/15 = 481
Your file value 41885 will be 41885/15 = 2792. By deviding by 15 you will not reach scrollbar limit of 32767 too soon.
0
 

Author Comment

by:rround
ID: 1453845
Ameba,

This still doesn't work.  I had already tried most of code in your suggestion but on the larger pictureboxes, it doesn't scroll far enough to reach some of the information, and on smaller pictureboxes, it scrolls too far.

Chabaud,

I think I must be missing something in calculating the effective size.  The Scaleheight is 7215 twips.  Now, If I have a picturebox and its final size is 41885, then I should have:
VScroll1.Max=picture1.height-scaleheight
Picture1.Top =-VScroll1.Value

right?  But using this, the bottom of the picturebox is missing.  When the final size is only 11985 then the scrollbar scrolls way past the bottom of the picturebox.  The problem is, each time my app runs, the size of the picturebox will vary.  What am I missing to make this work?
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1453846
You must also remove the scrollbar height if you want the bottom of picture to match with max of the scrollbar:

VScroll1.Max=picture1.height-scaleheight-VScroll1.heigth

0
 

Author Comment

by:rround
ID: 1453847
Ameba,

This still doesn't work.  I had already tried most of code in your suggestion but on the larger pictureboxes, it doesn't scroll far enough to reach some of the information, and on smaller pictureboxes, it scrolls too far.

Chabaud,

I think I must be missing something in calculating the effective size.  The Scaleheight is 7215 twips.  Now, If I have a picturebox and its final size is 41885, then I should have:
VScroll1.Max=picture1.height-scaleheight
Picture1.Top =-VScroll1.Value

right?  But using this, the bottom of the picturebox is missing.  When the final size is only 11985 then the scrollbar scrolls way past the bottom of the picturebox.  The problem is, each time my app runs, the size of the picturebox will vary.  What am I missing to make this work?
0
 

Author Comment

by:rround
ID: 1453848
Thanks Ameba,

I finally got it working....I was having a major brain cramp over this and I knew it should be relatively simple.

Thanks again.

Rob.
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
Excel Spreadsheet - Send email if certain value is selected. 14 86
Window placement 17 74
Reading the Contents of a Directory In Access VBA 5 58
Using "ScreenUpdating" 6 55
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now