Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-25
6
Medium Priority
?
2,757 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 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12151738
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
ID: 12157052
Change ScaleMode of picContainer and its container to pixels.
0
 
LVL 15

Expert Comment

by:ameba
ID: 12157156
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ksm
ID: 12165947
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
ID: 12168019
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
ID: 12172084
Hi Ameba:

Thank you.  I truly appeciate it.

Thank you.

ksm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

879 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