Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to scroll a picture box

Status
Not open for further replies.

Jn88

Programmer
Mar 11, 2001
55
US
I have a picture box with a large picture and I won’t to be able to scroll the picture can anyone help me?
 
'Picked this up somewhere, never tried it, maybe it'll work
'If not, maybe it'll give you a track to start on. Let us
'know if it does, or code that works if you get it going

' 1 create a new standard app
' 2 add a frame on your app
' 2a borderstyle = none
' 3 put a textbox or whatever on your FR
' AME!!
' 4 put a picturebox on your FRAME !!
' 4a borderstyle = none
' 5 add this code and voila your done!!!
'
Option Explicit
Dim this As Integer


Private Sub Form_Load()
this = 1
' set the frame totally down so you can'
' t see it
Frame1.Top = Me.Height
End Sub


Private Sub Timer1_Timer()
' the rate of scrolling down
frame1.Top = (Frame1.Top - 20)
' if the the bottom of the frame reaches
' the top of your
'app it goes down


If Frame1.Top <= 0 - Frame1.Height Then
'next picture on the frame
this = this + 1
'call the function &quot;here&quot;
Call here
Frame1.Top = Me.Height
End If
End Sub


Private Sub here()


Select Case this
' this code changes every time the frame
' passed the screen the picture on the fra
' me
'( you can change this in whatever you w
' ant)
Case Is = 1
Picture1 = LoadPicture(&quot;c:\ohio.jpg&quot;)
Case Is = 2
Picture1 = LoadPicture(&quot;c:\ohio1.jpg&quot;)
Case Is = 3
Picture1 = LoadPicture(&quot;c:\me2.jpg&quot;)
Case Is = 4
this = 1
End Select
End Sub

 
have two picture boxes, one inside the other and a vertical scroll bar.

You need
Private Sub VScroll1_Scroll()
picInner.Top = -VScroll1.Value
End Sub
Private Sub VScroll1_Change()
Call VScroll1_Scroll
End Sub
make picouter a sensible size on your form and give picinner a huge height. As they insist on saying, voila
 
Or Stretch Picture Box

'Add 2 Picture Boxes To Your Form. Add picture to Picture1 Picture Box
'Add 1 Command Button to your form.
'The following sample will stretch the first Picture Box to the size of the second Picture Box.
'Insert the following code to your form:

Private Sub Command1_Click()
Picture1.AutoSize = True
Picture2.AutoRedraw = True
Picture2.PaintPicture Picture1.Picture, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, _
0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
set a HscrollBar (named hbar) and a VscrollBar (named vbar)

a module with :

Private Sub ArrangeScrollbars()
Dim need_hgt As Single
Dim need_wid As Single
Dim got_hgt As Single
Dim got_wid As Single
Dim need_hbar As Boolean
Dim need_vbar As Boolean

' kijken welke scrollbar we nodig hebben
need_wid = Picture1.Width
need_hgt = Picture1.Height
got_wid = ScaleWidth - picScroller.Left
got_hgt = ScaleHeight - picScroller.Top

' hebben we de horizontale nodig
need_hbar = (got_wid < need_wid)
If need_hbar Then
got_hgt = got_hgt - hbar.Height
End If

' hebben we de verticale nodig
need_vbar = (got_hgt < need_hgt)
If need_vbar Then
got_wid = got_wid - vbar.Width
If Not need_hbar Then
need_hbar = (got_wid < need_wid)
If need_hbar Then
got_hgt = got_hgt - hbar.Height
End If
End If
End If
If got_hgt < 120 Then got_hgt = 120
If got_wid < 120 Then got_wid = 120

' toon de nodige scrollbar
If need_hbar Then
hbar.min = 0
hbar.max = got_wid - need_wid
hbar.SmallChange = got_wid / 3
hbar.LargeChange = _
(hbar.max - hbar.min) _
* need_wid / _
(got_wid - need_wid)
hbar.Visible = True
Else
hbar.Visible = False
End If
If need_vbar Then
vbar.min = 0
vbar.max = got_hgt - need_hgt
vbar.SmallChange = got_hgt / 3
vbar.LargeChange = _
(vbar.max - vbar.min) _
* need_hgt / _
(got_hgt - need_hgt)
vbar.Visible = True
Else
vbar.Visible = False
End If
End Sub

a pictureBox and a commondialog

Private Sub LoadFromFile_Click()
On Error Resume Next
With CommonDialog1
.CancelError = True
.Filter = &quot;Pictures(*.bmp;*.ico;*.gif;*.jpg;*.wmf)|*.bmp;*.ico;*.gif;*.jpg;*.wmf|&quot;
.Flags = cdlOFNHideReadOnly
.ShowOpen
If Err.Number = cdlCancel Then
Err.Clear
Exit Sub
End If
CurFoto = .FilterIndex - 1
FileName = .FileName
FileName.Visible = True

End With
ArrangeScrollbars

End Sub

Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top