|
-
Aug 18th, 2001, 09:36 PM
#1
Thread Starter
Addicted Member
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.
-
Aug 18th, 2001, 10:06 PM
#2
PowerPoster
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
-
Aug 18th, 2001, 10:08 PM
#3
Thread Starter
Addicted Member
Excellent i will start playing with this right now thank you.
-
Aug 18th, 2001, 10:09 PM
#4
Thread Starter
Addicted Member
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?
-
Aug 18th, 2001, 10:16 PM
#5
PowerPoster
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:
Private Sub Form_Load()
HScroll1.Max = pic_inside.Width - Pic_container.Width
VScroll1.Max = pic_inside.Height - Pic_container.Height
End Sub
Private Sub HScroll1_Scroll()
pic_inside.Left = -HScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
pic_inside.Top = -VScroll1.Value
End Sub
Regards
Stuart
-
Aug 18th, 2001, 10:34 PM
#6
Thread Starter
Addicted Member
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?
-
Aug 18th, 2001, 10:41 PM
#7
PowerPoster
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
-
Aug 18th, 2001, 10:51 PM
#8
Thread Starter
Addicted Member
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.
-
Aug 18th, 2001, 10:56 PM
#9
PowerPoster
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
-
Aug 18th, 2001, 10:57 PM
#10
Thread Starter
Addicted Member
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?
-
Aug 18th, 2001, 11:00 PM
#11
Thread Starter
Addicted Member
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
-
Aug 18th, 2001, 11:01 PM
#12
Thread Starter
Addicted Member
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
-
Aug 18th, 2001, 11:07 PM
#13
PowerPoster
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
-
Aug 18th, 2001, 11:13 PM
#14
Thread Starter
Addicted Member
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.
-
Aug 18th, 2001, 11:21 PM
#15
PowerPoster
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|