|
-
Mar 18th, 2003, 01:21 PM
#1
Thread Starter
Member
how to add a scroll to a pic. box when the image is bigger?
hi,how can i add a scroll to a picture box when the
size of the picture added is bigger than the picture box
size? and how can i get the picture scale when that occur anyway?
thnx
-
Mar 18th, 2003, 03:21 PM
#2
Frenzied Member
Scrolling picture box
Here's how to make a scrolling picture box.- Drop a picture box on the form
- Size it to your desired size
- Drop another picture box INSIDE the first one
- Drop a VScrollBar INSIDE the first PictureBox
- Drop an HScrollBar INSIDE the FIRST PictureBox
- Drop a TextBox INSIDE the FIRST PictureBox
- Paste the code below into your form window
- Either change the path for loading the PictureBox Picture in code, or remove it and set the Picture property manually
- Run the program and you will have a scrolling picture box
The easiest way to put the controls inside the first picture box (IMHO) is to drop them on the form, then select them all, cut them, select the first picture box, and then paste the controls inside.
You don't have to worry about the location of any controls except the first (container) PictureBox. The code does the rest:
VB Code:
Option Explicit
Private Sub Form_Load()
' Setup picture box
With Picture2
.AutoSize = True
.ZOrder 1
.Picture = LoadPicture("C:\Documents and Settings\a-rufusl\My Documents\My Pictures\forever 1.jpe")
.Move 0, 0
End With
' Setup textbox
With Text1
.BorderStyle = 0
.BackColor = Me.BackColor
.Enabled = False
.Height = HScroll1.Height
.Text = ""
.Width = VScroll1.Width
End With
' Setup scroll bars
ArrangeScrollBars
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = vbDefault
End Sub
Private Sub Form_Resize()
' Adjust scroll bars to new form size
ArrangeScrollBars
End Sub
Private Sub ArrangeScrollBars()
' Resize scroll bars to fit form, and set their max value (in relation to form size)
With HScroll1
.Move 0, Picture1.ScaleHeight - .Height, Picture1.ScaleWidth - VScroll1.Width
.Max = IIf((Picture2.ScaleWidth - Picture1.Width + VScroll1.Width) > 0, _
Picture2.Width - Picture1.ScaleWidth + VScroll1.Width, 0)
.SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
.LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
End With
With VScroll1
.Move Picture1.ScaleWidth - .Width, 0, .Width, Picture1.ScaleHeight - HScroll1.Height
.Max = IIf((Picture2.Height - Picture1.ScaleHeight + HScroll1.Height) > 0, _
Picture2.Height - Picture1.ScaleHeight + HScroll1.Height, 0)
.SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
.LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
End With
With Text1
.Left = HScroll1.Width
.Top = VScroll1.Height
.ZOrder 0
End With
End Sub
Private Sub HScroll1_Change()
Picture2.Move 0 - HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
Picture2.Move 0 - HScroll1.Value
End Sub
Private Sub VScroll1_Change()
Picture2.Move Picture2.Left, 0 - VScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
Picture2.Move Picture2.Left, 0 - VScroll1.Value
End Sub
Last edited by seaweed; Mar 18th, 2003 at 03:49 PM.
~seaweed
-
Mar 18th, 2003, 03:28 PM
#3
Frenzied Member
In case that wasn't what you were looking for...
If you just want the PictureBox to become the same size as the Picture, then set the AutoSize property to true.
If you want the picture to re-size to the size of the picture box, use an Image control instead and set the Stretch property to true.
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
|