Solved

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

Posted on 2004-09-25
6
2,532 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
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
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.

 

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

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now