Option Explicit Private Const SCROLLSENS As Long = 500 Private iTop As Long Private iLeft As Long Private Sub Form_Load() iTop = Me.Picture1.Top iLeft = Me.Picture1.Left Call SetScrollPositions Call SetScrollValues End Sub Private Sub Form_Resize() Call SetScrollPositions Call SetScrollValues End Sub Private Sub SetScrollPositions() ' scroll V Me.VScroll1.Top = 0 Me.VScroll1.Height = Me.ScaleHeight - Me.HScroll1.Height Me.VScroll1.Left = Me.ScaleWidth - Me.VScroll1.Width ' scroll H Me.HScroll1.Left = 0 Me.HScroll1.Width = Me.ScaleWidth - Me.VScroll1.Width Me.HScroll1.Top = Me.ScaleHeight - Me.HScroll1.Height End Sub Private Sub SetScrollValues() Dim x As Long Dim y As Long x = -(Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width) y = -(Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height) ' scroll V Me.VScroll1.Enabled = (y > 0) Me.VScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS) ' scroll H Me.HScroll1.Enabled = (x > 0) Me.HScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS) End Sub Private Sub HScroll1_Change() If Me.HScroll1.Value = Me.HScroll1.Max Then Me.Picture1.Left = Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width Else Me.Picture1.Left = iLeft - (Me.HScroll1.Value * SCROLLSENS) End If End Sub Private Sub VScroll1_Change() If Me.VScroll1.Value = Me.VScroll1.Max Then Me.Picture1.Top = Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height Else Me.Picture1.Top = iTop - (Me.VScroll1.Value * SCROLLSENS) End If End Sub
Private Sub SetScrollValues() Dim x As Long Dim y As Long x = -(Me.ScaleWidth - Me.Picture1.Width - Me.VScroll1.Width) y = -(Me.ScaleHeight - Me.Picture1.Height - Me.HScroll1.Height) ' scroll V Me.VScroll1.Enabled = (y > 0) Me.VScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS) ' scroll H Me.HScroll1.Enabled = (x > 0) Me.HScroll1.Max = IIf(y < 0, 0, y / SCROLLSENS) ' align picture at 0,0 If Not Me.VScroll1.Enabled Then Me.Picture1.Top = iTop If Not Me.HScroll1.Enabled Then Me.Picture1.Left = iLeft End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question