Solved

How to compensate for scrollbar.max of 32767 using visual basic 6

Posted on 2004-09-25
6
2,504 Views
Last Modified: 2013-12-20
Hi:

I'm using VB6 and am trying to compensate for the scrollbar max of 32767.  Here's what I'm trying to do.  I have a picture control within a picture control.  Let's call the outside picture control picContainer and the picture control within it picChild.  It's set up so that at design time if I move picContainer, picChild also moves.  My form is being used to view images and picChild is what contains the images.  When an image is loaded, picChild is resized to the size of the picture.  When picChild is larger than picContainer, picContainer contains a vertical scrollbar so that I can move picChild up and down to see the image (I'm just worrying about the vertical right now, forget about the horizontal).  I set my scrollbar (called fsb, for flat scroll bar) settings as follows:

fsb.Max = picChild.Height - picContainer.Height
fsb.SmallChange = Abs(fsb1.Max \ 16) + 1
fsb.LargeChange = Abs(fsb1.Max \ 4) + 1  

The program works perfectly except for when (picChild.Height - picContainer.Height) > 32767, the largest value the scrollbar max property can handle.  Attempting to set the max beyond that value of course causes an error to be generated.

Any ideas as to how to compensate for this max of 32767 so that I can still scroll to see the entire picture?  My goal is to be able to scroll up and down to see the entire picture but not scroll beyond the picture dimensions (I don't want the bottom of the picture scrolling up passed the top of the screen).

Looking forward to your replies.

Thanks.
ksm
0
Comment
Question by:ksm
  • 3
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
Comment Utility
What you can do is leave your scrollbar min at 0 and the max at 100.  Then you can use the current value of the scrollbar to compute the percentage of how far up/down the inner picturebox control should be moved.

Here is an example.  Create a new project and a TextBox, CommandButton, HorizontalScrollBar, VerticalScrollBar, PictureBox and a Windows Common Dialog Control.   Draw an additional PictureBox inside the first PictureBox.  Position the TextBox and CommandButton next to each other across the top of your form.  Make the first PictureBox take up the rest of the form.  The second PictureBox, HorizontalScrollBar and the VerticalScrollBar will be positioned at runtime via code.

Regards,

Idle_Mind

Option Explicit

Private horzMax As Single
Private vertMax As Single

Private Sub Form_Load()
    Text1.Locked = True
    Text1.Text = ""
    Command1.Caption = "Select Image"

    With Picture2
        .Move 0, 0
        .AutoSize = True
        .Width = Picture1.Width
        .Height = Picture1.Height
    End With

    With HScroll1
        .Top = Picture1.Top + Picture1.Height
        .Left = Picture1.Left
        .Width = Picture1.Width
        .Min = 0
        .Max = 100
        .SmallChange = 4
        .LargeChange = 10
    End With

    With VScroll1
        .Top = Picture1.Top
        .Left = Picture1.Left + Picture1.Width
        .Height = Picture1.Height
        .Min = 0
        .Max = 100
        .SmallChange = 4
        .LargeChange = 10
    End With
End Sub

Private Sub Command1_Click()
    On Error GoTo cancelled
   
    CommonDialog1.CancelError = True
    CommonDialog1.DialogTitle = "Select an Image to View"
    CommonDialog1.Filter = "Image Files (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|JPG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|GIF Files (*.gif)|*.gif"
    CommonDialog1.ShowOpen
    Text1.Text = CommonDialog1.fileName
    Call loadImage(CommonDialog1.fileName)
cancelled:
End Sub

Private Sub loadImage(ByVal fileName As String)
    On Error Resume Next
   
    If Dir(fileName) <> "" Then
        With Picture2
            .Move 0, 0
            .Picture = LoadPicture(fileName)
        End With

        horzMax = Picture2.Width - Picture1.Width
        With HScroll1
            .Value = 0
            If horzMax < 0 Then
                .Max = 0
                .Visible = False ' Optional
            Else
                .Max = 100
                .Visible = True ' Optional
            End If
        End With
               
        vertMax = Picture2.Height - Picture1.Height
        With VScroll1
            .Value = 0
            If vertMax < 0 Then
                .Max = 0
                .Visible = False ' Optional
            Else
                .Max = 100
                .Visible = True ' Optional
            End If
        End With
    End If
End Sub

Private Sub HScroll1_Change()
    If HScroll1.Max > 0 Then
        Picture2.Left = -(HScroll1.Value / HScroll1.Max) * horzMax
    End If
End Sub

Private Sub VScroll1_Change()
    If VScroll1.Max > 0 Then
        Picture2.Top = -(VScroll1.Value / VScroll1.Max) * vertMax
    End If
End Sub
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Change ScaleMode of picContainer and its container to pixels.
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:ksm
Comment Utility
Idle_Mind:
Percentage!  But of course!  I don't know why it wasn't just popping into my head.  Sometimes I believe I am also of idle mind.  Anyhow, thank you very much!  And your example worked perfectly.


Ameba:
I also appreciate the comments that you posted.  Thank you as well.


Thank you again!  I truly appreciate all the assistance.

ksm
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Thanks, ksm.
I think bitmaps' and controls' dimensions are limited to 32K pixels, but, maybe for some other purpose, there is a class by Karl E. Peterson, LongScroll.zip at http://www.mvps.org/vb/index2.html?samples.htm - it maps scrollbar values to Longs.

Good luck!
0
 

Author Comment

by:ksm
Comment Utility
Hi Ameba:

Thank you.  I truly appeciate it.

Thank you.

ksm
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now