Previous | Index | Next 

[PRB] ScrollBar controls ignore the LargeChange property

VB6 and .NET scrollbar controls differ for an important detail: if the .NET scrollbar’s LargeChange property is set to a value higher than 1, then the scrollbar’s Value property can’t reach the current Max value if the scrollbar indicator is moved to its “max” position. More precisely, this property can’t go higher than Max-LargeChange+1, therefore the problem manifests itself if (Max-Min) isn’t a multiple of LargeChange.

For this reason, by default all the scrollbar controls in the CodeArchitects.VBLibrary – namely, VB6HScrollBar, VB6VScrollBar, VB6WLHScroll, VB6WLVScroll, and VB6FlatScrollBar – ignore any assignment to the LargeChange property. More precisely, the property correctly retains the value assigned to it, but the new value isn’t assigned to the underlying .NET control. This behavior ensures that the application works as intended, even though the user will perceive a difference in how the scrollbar responds to mouse actions.

You can restore the standard .NET behavior by assigning False to the IgnoreLargeChange property that all these VB6*** scrollbar controls expose. You can perform this assignment in code or you can have this property set at design-time, by adding an appropriate WriteProperty pragma in the original VB6 application:

        ' enforce .NET behavior for Scroll1
        '##Scroll1.WriteProperty IgnoreLargeChange, False

Often this fix isn’t enough to ensure that a VB.NET scrollbar works exactly like the VB6 counterpart, and you also need to change the Max property in the Form_Load event handler, as follows:

        Private Sub Form1_Load() Handles Me.Load
            Scroll1.IgnoreLargeChange = False
            Scroll1.Max = Scroll1.Max + Scroll1.LargeChange - 1
        End Sub

For more information about LargeChange and SmallChange properties, read this KB article.

 

Previous | Index | Next