Präzise Steuerung der Anzeige einer Scrollbar
Author: Steffen Ploetz
(Stand der EN Seite vom 26.04.2024)
Die Breite des Thumb ist eine Funktion von ScrollBar.
PageStep und ScrollBar.
MinValue und ScrollBar.
Value und ist daher schwer zu kontrollieren. Der folgenden Codeschnipsel übersetzen relative Werte (Bereich 0.0 ... 1.0) in ScrollBar-Eigenschaften...
'' Sets the thumb width and scroll value as relative value in the range between 0.0 (lowest possible value) and 1.0 (highest possible value).
''
'' The **hScrollBar** argument defines the scroll bar to set the thumb width and scroll value for.
'' The **fThumb** argument defines the thumb width to set as relative value in the range between 0.0 and 1.0.
'' The **fValue** argument defines the scroll value to set as relative value in the range between 0.0 and 1.0.
'' Remarks: Good results can be achieved for scroll bars with with with these initial property values: MaxValue=100000, MinValue=500, PageStep=500, Step=500
Private Sub SetThumbAndScrollValue(hScrollBar As ScrollBar, fThumb As Float, fValue As Float)
Dim fThumbMin As Float = 0.005 ' The thumb should not be smaller than 5% of the extent of the scroll bar.
Dim iMax As Integer = hScrollBar.MaxValue
If fThumb < fThumbMin Then fThumb = fThumbMin
If fThumb > 1.0 Then fThumb = 1.0
If fValue < 0.0 Then fValue = 0.0
If fValue > 1.0 Then fValue = 1.0
hScrollBar.PageStep = fThumb * iMax
hScrollBar.MinValue = fThumb * iMax
hScrollBar.Value = fThumb * iMax + (iMax - hScrollBar.MinValue) * fValue
End
Der folgenden Codeschnipsel übersetzen die ScrollBar-Eigenschaften in einen relativen Wert (Bereich 0.0 ... 1.0)...
Beachten Sie die Tatsache, dass die statische Variable
fOldVal
nur einmal vorhanden ist und die Funktion folglich immer nur auf ein und denselben ScrollBar angewendet werden kann.
'' Determines the relative scroll value in the range between 0.0 (lowest possible value) and 1.0 (highest possible value).
''
'' The **hScrollBar** argument defines the scroll bar to get the scroll value for.
'' Returns: The relative value in the range between 0.0 and 1.0.
'' Remarks: Good results can be achieved for scroll bars with with with these initial property values: MaxValue=100000, MinValue=500, PageStep=500, Step=500
Private Function GetScrollValue(hScrollBar As ScrollBar) As Float
Dim iMaxValue As Integer = hScrollBar.MaxValue
Dim iMinValue As Integer = hScrollBar.MinValue
Dim fThumbVal As Float = hScrollBar.PageStep / iMaxValue
Dim fValue As Float = 0
Static fOldVal As Float = 0
If iMaxValue - iMinValue > 0.0 Then
fValue = Max(0, (hScrollBar.Value - fThumbVal * iMaxValue) / (iMaxValue - iMinValue))
fOldVal = fValue
Else
fValue = fOldVal
Endif
Return fValue
End
Änderungen der Seite
Präzise Steuerung der Anzeige einer Scrollbar: Steffen Ploetz - 25. April 2024