Scrolling di una Picture pił grande del suo contenitore
In un form inserire una PictureBox nominata Pic1, e dentro di essa
inserire un'altra PictureBox nominata Pic2.
Inserire inoltre una HScrollBar ed una VScrollBar.
Settare per prima le seguenti proprietą:
Form1.BorderStyle = vbSizable
Form1.ScaleMode = vbPixels
Pic1.AutoRedraw = True
Pic1.BorderStyle = vbFixedSingle
Pic1.ScaleMode = vbPixels
Pic2.AutoRedraw = False
Pic2.BorderStyle = vbnone
Pic2.ScaleMode = vbPixels
Infine inserire il seguente codice:
Option Explicit
Private Sub Form_Load()
Pic1.Move 0, 0
'Logicamente invece di [App.Path & "\ImageProva.bmp"]
inserirai l'immagine voluta.
Pic2.Picture = LoadPicture(App.Path & "\ImageProva.bmp")
Pic2.Move 0, 0
'se inizialmente, si vuol ridimensionare il form adattandolo
'all'immagine, utilizzare le seguenti linee di codice
'If Screen.Width > (Pic2.Width * 15.4) Then
' Me.Width = Pic2.Width * 15.4
'End If
'If Screen.Height > (Pic2.Height * 16.3) Then
' Me.Height = Pic2.Height * 16.3
'End If
End Sub
Private Sub Form_Resize()
'se minimizzato non effettua alcun controllo
'e sistemazione
If WindowState <> 1 Then
Pic1.Height = Me.ScaleHeight
Pic1.Width = Me.ScaleWidth
Pic2.Move 0, 0
If Pic2.ScaleHeight > Pic1.ScaleHeight Then
Pic1.Width = Me.ScaleWidth - 15
VScroll1.Visible = True
VScroll1.Move Pic1.Width + Pic1.Left, Pic1.Top, 15, Pic1.Height
Else
VScroll1.Visible = False
Pic1.Width = Me.ScaleWidth
End If
If Pic2.ScaleWidth > Pic1.ScaleWidth Then
Pic1.Height = Me.ScaleHeight - 15
HScroll1.Visible = True
HScroll1.Move Pic1.Left, Pic1.Top + Pic1.Height, Pic1.Width, 15
Else
HScroll1.Visible = False
Pic1.Height = Me.ScaleHeight
End If
SetScrollBars
End If
End Sub
Private Sub HScroll1_Change()
Pic2.Left = HScroll1.Value
End Sub
Private Sub HScroll1_GotFocus()
Pic1.SetFocus
End Sub
Private Sub VScroll1_Change()
Pic2.Top = VScroll1.Value
End Sub
Private Sub VScroll1_GotFocus()
Pic1.SetFocus
End Sub
Private Sub SetScrollBars()
VScroll1.Min = 0
VScroll1.Max = (Pic2.ScaleHeight - Pic1.ScaleHeight) * -1
VScroll1.SmallChange = 1
VScroll1.LargeChange = Pic1.ScaleHeight / 4
HScroll1.Min = 0
HScroll1.Max = (Pic2.ScaleWidth - Pic1.ScaleWidth) * -1
HScroll1.SmallChange = 1
HScroll1.LargeChange = Pic1.ScaleWidth / 4
End Sub
Testato su: Windows 98, Windows Me, Windows 2000 Professional