I have a scanned image that is bigger than the screen when it gets displayed on the screen. I don't really want to size down the image so I would like to be able to add scroll bars to the image. How do I go about adding a scroll bar to a picturebox so it will scroll the image when I move the scroll bar?
It seems like I have did this before, several years back but I don't remember how I did it. How are you 'attaching' picPicture to picWindow?
I know if I use what you wrote and I scan in an 8.5x11 page I can scroll as long as I'm scanning in color. I want to scan in black and white. When I do that I end up getting and Overflow error highlighted on VScroll1.Max =. I'm not using two pictureboxes rather only one with the scroll bars setting at the edge of the screen. I'm not sure if having the extra picturebox would take care of the problem or not but to try I would have to figure out how to 'attach' one to the other first.
You have to use two pictureboxes in order to make the scrolling work. The idea is that the scrollbars move the "inner" picturebox -- the one that holds the image -- around inside the "outer" picturebox. If you only use one picturebox, when you scroll it it'll look cheesy and amateurish as it clearly slides under the scrollbars. (Or worse, slides over the scrollbars.)
The scrollbars stay outside both pictureboxes for that exact reason.
Here's generic code to handle pretty much everything you need. The control names:
picScroll: Outer picturebox that handles the scrolling.
picClient: Inner picturebox with the actual image. Make its container picScroll by copy & pasting it.
scrHorizontal: Horizontal scroll bar.
scrVertical: Vertical scroll bar.
The scroll bars should be on the form, not inside any picturebox.
Here's generic code to handle pretty much everything you need. The control names:
picScroll: Outer picturebox that handles the scrolling.
picClient: Inner picturebox with the actual image. Make its container picScroll by copy & pasting it.
scrHorizontal: Horizontal scroll bar.
scrVertical: Vertical scroll bar.
The scroll bars should be on the form, not inside any picturebox.
It's either picClient or picScroll...too early for me to think too hard about it, but just try one and if it doesn't work try another (and if still not, try other elements that it could be...in fact, did you really need to post asking?)
You guys may not have noticed, but this thread is 14 years old.
What difference does it make how old the topic is if there is still no correct solution on one picturebox. I also really need to make scrollbars for the image. But I want to use one picture box. How can this be done? How do I move the image left and right if I have only one picturebox on my form?
Since no one has ever created a technology for scrolling an image based on only one picturebox, I had to do it myself today.
I want to draw attention to the fact that there are much fewer lines of code in my implementation. My version is much simpler than yours.
Code:
Option Explicit
Dim cPic As StdPicture
' We will scroll the picture here from 0 to -319 (320 in total)
Private Sub DrawFit(ByVal hDC As Long, ByVal cPic As IPicture, ByVal NewX As Long)
Dim lsw As Long
Dim lsh As Long
lsw = CLng(((cPic.Width / 2540) * 1440) / Screen.TwipsPerPixelX)
lsh = CLng(((cPic.Height / 2540) * 1440) / Screen.TwipsPerPixelY)
cPic.Render hDC, -NewX, 0, lsw, lsh, 0, cPic.Height, cPic.Width, -cPic.Height, ByVal 0&
End Sub
Private Sub Paint_Picture()
Dim NewValueX As Long
NewValueX = HScroll1.Value
Me.Caption = NewValueX
Picture1.Cls
DrawFit Picture1.hDC, cPic, NewValueX
End Sub
Private Sub HScroll1_Change()
Paint_Picture
End Sub
Private Sub HScroll1_Scroll()
Paint_Picture
End Sub
Private Sub Form_Load()
Set cPic = LoadPicture(App.Path & "\123456789.jpg")
HScroll1.Max = Picture1.ScaleWidth
Paint_Picture
End Sub
Here is another example using the scrollbar from the legendary user The Trick. I have placed the scroll bar here on the form, behind the picture. However, given that the control itself is transparent, it could be installed even inside the picturebox.
What way do you recommend?
I have tried clsTrickSubclass2 from Trick but the IDE crashes
Is a Subclass needed for this?
I personally would not recommend anything, as I have no idea how to do this. But for some reason I was sure that it was possible to do without subclassing...