|
-
Dec 29th, 2005, 10:31 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Assigning scroll bars to a picture box.
Basically I want to load an image from file into a picture box and keep the picture box at the same size, but be able to scroll around the image using scroll bars.
I have tried using two scroll bar controls for this, but I can't seem to get it working how I would like.
Anyone got a decent method or tips on how I can do this?
Cheers
-
Dec 29th, 2005, 10:36 AM
#2
Re: Assigning scroll bars to a picture box.
See Martin's example here.
-
Dec 29th, 2005, 10:45 AM
#3
Re: Assigning scroll bars to a picture box.
add 2 scroll bars (1-vert, 1 horz), and 2 picture boxes (first acts like a container and another contains the picture). and try this code: (you may need to modify a bit, not tested)
VB Code:
Private Sub Form_Load()
VScroll1.Height = picture1.Height
HScroll1.Width = picture1.Width
VScroll1.Max = picture2.Height - picture1.Height
HScroll1.Max = picture2.Width - picture1.Width
VScroll1.SmallChange = 100
HScroll1.SmallChange = 100
VScroll1.LargeChange = picture1.Height
HScroll1.LargeChange = picture1.Width
End Sub
Public Sub myKeyCodefunc(KeyCode As Integer)
Dim myScrValue As Double
Dim pageheight As Integer
pageheight = Me.VScroll1.Height
If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
If KeyCode = vbKeyPageDown Then
myScrValue = -Me.picture2.Top + pageheight
Else
myScrValue = -Me.picture2.Top - pageheight
End If
If myScrValue > Me.VScroll1.Max Then
myScrValue = Me.VScroll1.Max
Me.picture2.Top = -Me.VScroll1.Max
End If
If myScrValue > 0 Then
Me.VScroll1.Value = myScrValue
Else
Me.VScroll1.Value = 0
End If
End If
End Sub
Private Sub HScroll1_Change()
picture2.Left = -(HScroll1.Value)
End Sub
Private Sub Picture2_KeyDown(KeyCode As Integer, Shift As Integer)
myKeyCodefunc KeyCode
End Sub
Private Sub VScroll1_Change()
picture2.Top = -(VScroll1.Value)
End Sub
-
Dec 29th, 2005, 10:50 AM
#4
Thread Starter
Addicted Member
Re: Assigning scroll bars to a picture box.
Thanks Hack, that's just what I needed. (I should have searched really)
Thanks Harsh Gupta too.
*Solved*
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
|