<post cleared, time for final result>
Got it all working very nicely, but it took some workaround:
vb Code:
Public Class ScrollData Sub New(ByVal control As Control, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL) Me.SetData(control.Handle, scroll, flags) End Sub Sub New(ByVal handle As IntPtr, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL) Me.SetData(handle, scroll, flags) End Sub Public Sub SetData(ByVal handle As IntPtr, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL) Me.flags = flags Dim s As New SCROLLINFO(Me.flags) SCROLLINFO.GetScrollInfo(handle, scroll, s) Me.handle = handle Me.scroll = scroll Me.Minimum = s.nMin Me.Maximum = s.nMax Me.Position = s.nPos Me.Page = s.nPage Me.TrackPosition = s.nTrackPos End Sub Public flags As mask Public handle As IntPtr Public scroll As Bar Public Minimum As Integer Public Maximum As Integer Public Page As UInteger Public Position As Integer Public TrackPosition As Integer Public Function Update(Optional ByVal redraw As Boolean = True) As Integer Dim s As New SCROLLINFO(Me.flags) s.nMin = Me.Minimum s.nMax = Me.Maximum s.nPos = Me.Position s.nPage = Me.Page s.nTrackPos = Me.TrackPosition Return SCROLLINFO.SetScrollInfo(Me.handle, Me.scroll, s, redraw) End Function Public Enum Bar As Integer Horizontal = 0 Vertical = 1 Client = 2 Both = 3 End Enum Public Enum Mask As UInteger Range = &H1 Page = &H2 Position = &H4 DisableNoScroll = &H8 TrackPosition = &H10 ALL = Range Or Page Or Position Or TrackPosition End Enum Private Structure SCROLLINFO Public Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO) As Boolean Public Declare Function SetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO, ByVal redraw As Boolean) As Integer Sub New(ByVal mask As Mask) Me.cbSize = Marshal.SizeOf(Me) Me.fMask = mask End Sub Private cbSize As UInteger Private fMask As Mask Public nMin As Integer Public nMax As Integer Public nPage As UInteger Public nPos As Integer Public nTrackPos As Integer End Structure End Class
Usage:
Added the API structure inside a class so I was able to hold the scroll type loaded and the Handle of it, since passing the arguments all the time is a bit useless.Code:Dim s As New ScrollData(TextBox1, ScrollData.Bar.Vertical) s.Position += 1 s.Update()
Thanks all, especially Paul for reviving the ScrollInfo idea and for the previous examples.![]()




Reply With Quote