Solved

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

Posted on 2004-09-25
6
2,616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to compare ms sql hashbytes results within vb6 5 108
Search combo error "Data Type Mismatch in Criteria Expression" 2 98
Advice in Xamarin 21 121
Set WorkSheet  not Working 9 62
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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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