'Codice d'esempio per lo spostamento di un controllo "Imagebox" all'interno
'di un'altro controllo (es. picturebox) con funzioni di "contenitore".
'By Claudio Gucchierato 1999
Option Explicit
Dim startx As Integer 'coordinata(x) iniziale per lo spostamento dell'immagine
Dim starty As Integer 'coordinata(y) iniziale per lo spostamento dell'immagine
Dim BordoTreD As Integer 'eventuale spessore bordo 3D del controllo contenitore
Private Sub Command3_Click()
MsgBox "craeato da gius"
End
End Sub
Private Sub Form_Load()
'dichiarazione che serve per tener conto dello spessore dell'eventuale
'cornice tridimensionale del controllo contenitore (picturebox)
If picContainer.Appearance = 1 And picContainer.BorderStyle = 1 Then
'bordo con effetto tridimensionale
BordoTreD = 60 'spessore del bordo in twips
'bordo normale
ElseIf picContainer.Appearance = 0 And picContainer.BorderStyle = 1 Then
BordoTreD = 30 'spessore del bordo in twips
Else 'nessun bordo
BordoTreD = 0
End If
End Sub
Private Sub imgImmagine_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
startx = X 'memorizzo la posizione (X) di partenza
starty = Y 'memorizzo la posizione (Y) di partenza
End Sub
Private Sub imgImmagine_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then 'se č premuto il pulsante SX del mouse........
Call SpostaImmagine(X, Y) 'richiamo la sub
End If
End Sub
Sub SpostaImmagine(X As Single, Y As Single)
Dim orizzontale As Double
Dim verticale As Double
'spostamento "Left" e "Top" da eseguire
orizzontale = imgImmagine.Left + (X - startx)
verticale = imgImmagine.Top + (Y - starty)
'>>>>>>>>>>>immagine pių piccola del controllo picturebox
If imgImmagine.Width < picContainer.Width And imgImmagine.Height < picContainer.Height Then
imgImmagine.Left = orizzontale
If imgImmagine.Left <= 0 Then imgImmagine.Left = 0
If imgImmagine.Left + imgImmagine.Width >= picContainer.Width - BordoTreD Then
imgImmagine.Left = picContainer.Width - imgImmagine.Width - BordoTreD
End If
imgImmagine.Top = verticale
If imgImmagine.Top <= 0 Then imgImmagine.Top = 0
If imgImmagine.Top + imgImmagine.Height >= picContainer.Height - BordoTreD Then
imgImmagine.Top = picContainer.Height - imgImmagine.Height - BordoTreD
End If
Else
'>>>>>>>>>>immagine pių grande del controllo picturebox
If imgImmagine.Left + (X - startx) > 0 Then
orizzontale = 0
ElseIf imgImmagine.Left + (X - startx) <= picContainer.Width - imgImmagine.Width - BordoTreD Then
orizzontale = picContainer.Width - imgImmagine.Width - BordoTreD
End If
imgImmagine.Left = orizzontale
If imgImmagine.Top + (Y - starty) > 0 Then
verticale = 0
ElseIf imgImmagine.Top + (Y - starty) <= picContainer.Height - imgImmagine.Height - BordoTreD Then
verticale = picContainer.Height - imgImmagine.Height - BordoTreD
End If
imgImmagine.Top = verticale
End If
End Sub
Private Sub Command1_Click()
imgImmagine.Picture = Image2.Picture
imgImmagine.Top = 0
imgImmagine.Left = 0
End Sub
Private Sub Command2_Click()
imgImmagine.Picture = Image1.Picture
imgImmagine.Top = 0
imgImmagine.Left = 0
End Sub