Vscroll limite [ -32768 ~ 32767 ]

Contenu du snippet

VScroll se limite malheureusement à -32,768 a 32,767.

Ce code permet d'avoir un Vscroll pouvant allez de -2147483648 a 2147483647.

Ajoutez un 'UserControl' et sur celui si, ajouter un simple Vscroll.

Source / Exemple :


Public Event Scroll()
Public Event Change()

Private VLargeChange As Long
Private EnsValue As Long
Private Vl As Long
Private Total As Double
Private VMax As Double
Private VMin As Double
Private ScrOn As Boolean

Private Sub UserControl_Resize()
  VScroll1.Width = UserControl.Width - 32
  VScroll1.Height = UserControl.Height - 32
End Sub

Private Sub VScroll1_Change()
  If ScrOn = True Then ScrOn = False: RaiseEvent Change

  Change = VScroll1.Value - EnsValue
  If Change = 0 Then Exit Sub
  
  If Abs(Change) = 2 Then
    Vl = Vl + (VLargeChange * (Change / 2))
    SetVscrollBar
    RaiseEvent Change
  End If
  
  If Abs(Change) = 1 Then
    Vl = Vl + Change
    SetVscrollBar
    RaiseEvent Change
  End If
  EnsValue = VScroll1.Value
End Sub

Private Sub VScroll1_Scroll()
  ScrOn = True
  Vl = Int((VScroll1.Value / VScroll1.Max) * Total) + VMin
  EnsValue = VScroll1.Value
  RaiseEvent Scroll
End Sub

Sub SetVscrollBar()
  If Total = 0 Then VScroll1.Max = 0: Vl = VMax: Exit Sub Else VScroll1.Max = 32767
  If Total < 32767 Then VScroll1.Max = Total Else VScroll1.Max = 32767
  If Vl > VMax Then Vl = VMax
  If Vl < VMin Then Vl = VMin
  EnsValue = Int(((Vl - VMin) / Total) * VScroll1.Max)
  VScroll1.Value = EnsValue
End Sub

Private Sub UserControl_Initialize()
  VScroll1.LargeChange = 2
End Sub

Public Property Let LargeChange(ByVal V As Long)
  VLargeChange = V
End Property

Public Property Get LargeChange() As Long
  LargeChange = VLargeChange
End Property

Public Property Let Value(ByVal V As Long)
  Vl = V
  SetVscrollBar
End Property

Public Property Get Value() As Long
  Value = Vl
End Property

Public Property Get Min() As Long
  Min = VMin
End Property

Public Property Let Min(ByVal Value As Long)
  VMin = Value
  Total = Abs(VMin - VMax)
  SetVscrollBar
End Property

Public Property Get Max() As Long
  Max = VMax
End Property

Public Property Let Max(ByVal Value As Long)
  VMax = Value
  Total = Abs(VMin - VMax)
  SetVscrollBar
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  VMin = PropBag.ReadProperty("Min", 0)
  VMax = PropBag.ReadProperty("Max", 32767)
  Vl = PropBag.ReadProperty("Value", 0)
  VLargeChange = PropBag.ReadProperty("LargeChange", 1)
  Total = Abs(VMin - VMax)
  SetVscrollBar
  
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  Call PropBag.WriteProperty("Min", VMin, 0)
  Call PropBag.WriteProperty("Max", VMax, 32767)
  Call PropBag.WriteProperty("Value", Vl, 0)
  Call PropBag.WriteProperty("LargeChange", VLargeChange, 1)
  Total = Abs(VMin - VMax)
  SetVscrollBar
End Sub

Conclusion :


La Technique est plutôt simple, fallait juste y penser :)

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.