Results 1 to 16 of 16

Thread: [RESOLVED] Scrollbar thumb (slider) size.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] Scrollbar thumb (slider) size.

    Can anyone help me with a scroll bar problem.

    I have a picture within a form which has an HScroll and VScroll scroll bars but the size of the thumb or slider isn't proportional to the missing portion of the picture.

    I know it has to do with the
    HScroll1.SmallChange
    HScroll1.LargeChange
    VScroll1.SmallChange
    VScroll1.LargeChange
    variables but I just don't understand them. No matter what I do to test on them it doesn't make sense.

    Basically I need the variables to be a function of the form size and the picture size. ie form1.height/picture1.height

    At the same time can someone explain what the difference between picture.height and picture.scaleheight?

  2. #2
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: Scrollbar thumb (slider) size.

    It sounds like you need to set the scroll bars max and min properties to reflect the image size... the small change is the value change when you click the arrow and the large change is the value change when you click between the arrow and the slider

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    I found some code on microsoft's web site for adding scroll bars to a picture. Here is the link to the thread. I still don't understand how to modify it to get it working correctly. They have

    VB Code:
    1. HScroll1.Max = Picture1.Width - VScroll1.Left
    2.    VScroll1.Max = Picture1.Height - HScroll1.Top

    Has anyone any suggestions on how to change it so that it starts with a long slide bar as soon as form1.width<picture1.width?

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Scrollbar thumb (slider) size.

    Well, if you post your code, then we should be able to help you better.

    But as a general rule, I would calcuate the smallchange and largechange like this:
    VB Code:
    1. HScroll1.SmallChange = HScroll1.Max * 0.01
    2. If HScroll1.SmallChange <= 0 Then HScroll1.SmallChange = 1
    3. HScroll1.LargeChange = HScroll1.Max * 0.1
    4. If HScroll1.LargeChange <= 0 Then HScroll1.LargeChange = 1
    Use the same formula for the VScroll1

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Scrollbar thumb (slider) size.

    Quote Originally Posted by sgrya1
    At the same time can someone explain what the difference between picture.height and picture.scaleheight?
    You can change the scale, and it won't change the actual size of the picturebox.

    Scale is used the set the "virtual" size of the picturebox

    For example, if you have a picturebox with height 100, you can set it's ScaleHeight to 1000, then any object that you put INSIDE the picturebox, will have a size depending on it's scale, so if you put another object inside the picturebox, and you make it the same size as the picturebox, then it's height will be 1000 because it's parent picturebox has it's scale to 1000.

    Anyways, I also attached a picture, maybe you will understand better when you actually see the sample numbers...
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    Thanks CVMichael.

    Sort of understood why a picture needed to have scales but that explains it very clearly.

    Attached is a shell of a project with your suggestions.

    There's something wrong now with the max properties assigned to the scroll bars. Can you please look at it to see what is wrong.
    Attached Files Attached Files

  7. #7
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Scrollbar thumb (slider) size.

    I made quite a few changes, see if you like it ?
    Attached Files Attached Files

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    Thanks for looking at it but I still need some adjustments.

    Attached is the original.

    With the original the scroll bars are not visible until the size of the form is less than the size of the picture. This is what I want. But the problem is that as soon as the form is smaller than the picture the sliders appear but are about 1/5 of the size of the form. I'd like it so that that as when the form is a little bit smaller than the size of the picture, the sliders appear but are almost the length of the form and reduce when the form is resized smaller. Can you please look at it again?
    Attached Files Attached Files
    Last edited by sgrya1; Nov 29th, 2006 at 06:19 AM.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    Is anyone able understand what is wrong with the slider code? It's driving me nuts.

    Below is the explaination for the paramaters but it seems that they are bugged. No matter what I change it doesn't do what I think it should.

    Parameters
    Min Usually set to zero or one
    Max Set this to the number of rows in the file minus the number of rows displayed. If you want to scroll past the last row, then set it larger.
    Value Where the slider is located.
    LargeChange Amount Value is changed when the user clicks above or below the slider, or presses PgUp or PgDn keys.
    SmallChange Amount Value is changed when the user clicks an arrow or presses the up and down arrow keys.

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Scrollbar thumb (slider) size.

    I finally understand what you wanted, you want to scroll when the form is smaller than the picture, not the other way around (as I originally understood)

    But it looks OK to me...
    I made the SmallChange and LargeChange static, maybe that's the result you want, take a look

    I also placed some lines in the picture box, to be able to actually see it moving around
    Attached Files Attached Files

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    Thanks again CVMichael. I might be getting pedantic about it but it still isn't behaving like normal windows sliders.

    For example in Word if half the page is missing, the slider is half the length of the scrollbar but the in the example posted it is about 1/10th.
    Attached Images Attached Images   

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    I've found an answer but I don't understand how it works. It was just a stab that seems to do the trick.

    VB Code:
    1. HScroll1.SmallChange = Picture1.Width / 10
    2.     HScroll1.LargeChange = Picture1.Width / 2
    3.     VScroll1.SmallChange = Picture1.Height / 10
    4.     VScroll1.LargeChange = Picture1.Height / 2

    Thanks for your help again. You showed me what I should be tweaking.
    Attached Files Attached Files

  13. #13
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Scrollbar thumb (slider) size.

    Maybe this is what your looking for ?
    VB Code:
    1. HScroll1.SmallChange = Picture1.Width / 10
    2.     HScroll1.LargeChange = Picture1.Width - HScroll1.Max
    3.     VScroll1.SmallChange = Picture1.Height / 10
    4.     VScroll1.LargeChange = Picture1.Height - VScroll1.Max

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Scrollbar thumb (slider) size.

    YEP! That's it!

    Thankyou. Sorta think I understand it too.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: [RESOLVED] Scrollbar thumb (slider) size.

    CVMichael,

    Not sure why this bug is occuring. Hoping you can help me out again.

    Every now and again when I switch to a different application I come back to my progam to find that I get an error saying run-time error "380"
    "Invalid Property Value"
    When I press the debug button it flags
    VScroll1.LargeChange = Picture1.Height - VScroll1.Max
    as being the problem.

    I'd like to shell down my program to show it to you but was wondering if you had any ideas before I try.
    Last edited by sgrya1; Dec 4th, 2006 at 05:48 PM.

  16. #16
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: [RESOLVED] Scrollbar thumb (slider) size.

    It's probably because the value that is assigned to the VScroll1.LargeChange is less than 1.

    This happens especially when you minimize the form, or maximize it, also when you make the form too small.

    Just ignore the error, or I should say, just make the program ignore the error
    So, at the beginning of Form_Resize(), put this:
    VB Code:
    1. Private Sub Form_Resize()
    2.     On Error Resume Next
    3.     ' .... the rest of the code
    I always do that in the Form_Resize(), it's the only time when I actually want to ignore an error

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width