让 Scrollbar Max 一样长? - Vb6

问题描述 投票:0回答:2

我正在开发我的 vb6 项目,我需要滚动条最大值达到 40000。尽管我可以假设最大值约为 32000,因为滚动条最大值是一个整数。我该如何改变这个?

谢谢,

凯文

vb6 scroll integer scrollbar long-integer
2个回答
5
投票

为什么需要这样做?考虑将范围设置为 0 到 100,或 0 到 1000(基本上是文档大小的百分比),然后从该范围缩放到您需要的范围。

编辑: 例如,如果您的文档有 40,000 行,请将滚动条最大值设置为 100。读取该值时,将其乘以文档大小与滚动条最大大小的比率。当滚动条拇指位于 50 的中间时,您将得到 50 * (40,000 / 100),或 20,000。

您必须在 VB6 中使用

long


0
投票

您不能设置超过 32767 的最大值,因为它是 Integer 类型,并且这是 32 位 Integer 的最大值。我的解决方案是建立

Dim lCurrentRow as Long 
Dim dblMultiplier as Double
Dim lPreviousValue as Long

当你的结果集低于或等于32767时你可以设置

dblMultiplier = 1
vScrollBar1.Min = 1
vScrollBar1.Max = ResulSet.Count

当它变大时,你设置:

dblMultiplier = Resulset.Count / 32767 

vScrollBar1.Min = 1
vScrollBar1.Max = 32767

当您直接滚动滚动条获得值时,您应该应用乘数

lCurrentLine = vScrollBar1.Value * dblMultiplier

所以你总是有一个位置,但这意味着当 dblMultiplier 大于 1 时,行数将多于滚动条位置,你应该捕获更改事件并评估何时进行了小更改。类似这样的东西:

Private Sub VScrollBar1_Change()
    If Abs(VScrollBar1.Value - lPreviousValue) = VScrollBar1.SmallChange Then
        If Sgn(VScrollBar1.Value - lPreviousValue) >= 0 Then
            'That means we have increased the value
            lCurrentLine = lCurrentLine + VScrollBar1.SmallChange
            If lCurrentLine > Resulset.Count Then lCurrentLine = Resulset.Count
        Else
            'That means we have decreased the value
            lCurrentLine = lCurrentLine - VScrollBar1.SmallChange
            If lCurrentLine < 1 Then lCurrentLine = 1
        End If
    Else
        lCurrentLine = VScrollBar1.Value * dblMultiplier
    End If
    'That captures the scrollbar current value for future changes
    lPreviousValue = VScrollBar1.Value
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.