Results 1 to 15 of 15

Thread: Scroll bar - rephrasing my question

  1. #1

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171

    Question Scroll bar - rephrasing my question

    I was talking to a guy over email about this question and he told me how to phrase it to where I may be able to get a good answer.


    I have a form - within that form I have many other things but one of those is a picturebox that I have set to a specific size

    The images that are assigned to that pixel box are almost twice the size of the picbox - (the images themselves are 800 pixels by 600 pixels.

    Now of course I can make the picbox resize to fit the size of the image but what i would prefer to do is keep the picbox the exact same size and add scroll bars to it so that you can scroll left and right - up and down - etc to view all of the image.

    I have been unable to find a good tutorial on this. The only things that I have found assume the picbox takes up the entire form. Mine does not. I have attached an image to show you what my picbox looks like on the form so you can better understand why i want scroll bars.


  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    I'll give u the concept and let u play around with it for a while. if u cant work it out from this then pls repost and i will prepare some code for you.

    What u need to do is put a picture box (Pic_Inside) within a picture box (Pic_Container).

    Pic_Inside is set to the FULL size of the picture.
    Pic_Container is set to the size u want to display.
    It doesnt really matter if u put the horizontal and vertical scroll bar controls inside the pic_Container or outside but not within the Pic_Inside picture. Is prob easiest to put the scroll bars outside of the pics altogether

    The scroll bars max values are given difference in the widths of the picture boxes. So, say pic_inside is 800 and pic_container is 200. The scroll bar maximum would be 600. Each scroll movement u set the left property of pic_inside to NEGATIVE the scroll value. So, say u scroll to 500 (0 to 600) the left property of Pic_Inside becomes negative 500 (ie - scrollbarHor.Value)

    This is same for vertical bars.

    Play around with this and see how u go.
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    Excellent i will start playing with this right now thank you.

  4. #4

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    I do have one question that i do not understand -

    I undertsand what you mean by putting a pic box inside another pic box - however is there any spcific code I need to know so that the form knows that one pic box is inside another?

    Or is it something I change in the properties?

    or nothing at all?

  5. #5
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi again
    When u create the second picture box. You create it inside the first one. Or u can create it on form... cut it and then highlight first picture box and Paste.

    here is some code to get u going. NB U can add more events for scroll bar such as Change event etc and also play around with the Small Change properties to get ur desired results. But u will see idea and get what u want with some experimentation
    VB Code:
    1. Private Sub Form_Load()
    2.     HScroll1.Max = pic_inside.Width - Pic_container.Width
    3.     VScroll1.Max = pic_inside.Height - Pic_container.Height
    4. End Sub
    5.  
    6. Private Sub HScroll1_Scroll()
    7.     pic_inside.Left = -HScroll1.Value
    8. End Sub
    9.  
    10. Private Sub VScroll1_Scroll()
    11.     pic_inside.Top = -VScroll1.Value
    12. End Sub
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  6. #6

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    The good news is I got it to scroll :-)

    I still have to work with getting the scroll to not go so far - it scrolls over so far you see the back of the picturebox for quite a few pixels.



    Any tips?

  7. #7
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi again
    That shouldnt happen. I just checked code i posted and it doesnt do that. Did u copy and paste the code or retype? Other things that may affect it are
    1) Have u manually adjusted scale heights/widths of pictures? If u adjust the scaling of the container picture that will affect the positioning of the inside picture
    2) Set pictures to flat instead of 3D and/or remove borders

    Let me know how u go
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  8. #8

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    I posted a pic so you can see what it is doing. The dark gray area is the picturebox showing up when you scroll over.


  9. #9
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Can u pls post just the relevant parts of code where u set scroll bar maximum values and also the scroll bar change and scroll events. Cos as I said .. the original code will work unless u have adjusted for scaling etc. It looks to me like the scroll bar max property has not been set to the difference between the widths of each picture box.
    regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  10. #10

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    Ok well before you respond I figure out that problem

    Now a new problem arrised -

    The scroll bar buttons do not move at all - they are the length of the entire bar itself?

  11. #11

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    Ok well then I don't understand what else I should be adding because I only used your code exactly how it was.

    Sorry to be such a bother on this - I hate being a newbie

  12. #12

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    Code:
    Private Sub Form_Load()
        HScroll1.Max = imgFile.Width - imgContainer.Width
        VScroll1.Max = imgFile.Height - imgContainer.Height
    End Sub
    
    Private Sub HScroll1_Scroll()
        imgFile.Left = -HScroll1.Value
    End Sub
    
    Private Sub VScroll1_Scroll()
        imgFile.Top = -VScroll1.Value
    End Sub

  13. #13
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    LOL is no probs at all
    I see that u used img as references to the controls... The inside picture box is indeed a Picture control isnt it and not an Image control? See, the Image control may automatically resize if Stretch is set to false.

    If it is an image control then u need to move the calculation of the difference from the Form Load event (to Form Activate) or do a Me.Show before u do the calcs in Form Load
    Hope this is it!! haha
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  14. #14

    Thread Starter
    Addicted Member dhighlander's Avatar
    Join Date
    Aug 2001
    Location
    Houston
    Posts
    171
    Actually it is a picture control.

    When i started this app I called the picbox "img" by mistake and I have just never taken the time to fix it.

    I actually did get this work by setting the inside picbox to the exact width and height of the images I will be openning.

    thanks for all your help.

  15. #15
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Originally posted by dhighlander
    Actually it is a picture control.

    When i started this app I called the picbox "img" by mistake and I have just never taken the time to fix it.

    I actually did get this work by setting the inside picbox to the exact width and height of the images I will be openning.

    thanks for all your help.
    Ok then why not make ur inside picture an Image control? Are there any Picture control properties that u need that makes this impractical? If u use an Image control u will have the automatic resizing done for u so no coding. Use exactly same code. I originally suggested Picture control as inside control becos it can be a container for other controls eg pics, textboxes etc... but if u only want a picture then definitely use an Image control for the internal control ie the one I called Pic_inside.
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

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