hmm oke i admid my code was a bit of mess. i cleared it out a bit and made a example program so you can see how it works. Please follow the below steps. 1. start a new form project 2. Add is Listbox. set the name to txtscroll and the size to 254; 381 3. Add a button, call this one btnadd 4. copy paste the following code into the project (under the form you just made)
Imports System.Runtime.InteropServices
Public Class Form1
#Region "declarations"
Dim WithEvents scrollhandler As MyListener 'class that will watch windows to see if your scrolling
Private scrolled As Boolean = False 'boolean you can use to flip if a message box was displayed or not...(so it wont loop the messagebox.show)
Private maxscroll As Int64 'int used to store the max value of the scrollbar
Private index As Int32 = 0 'used for random loops to fill the txtscroll
Private Const SB_HORZ As Integer = &H0
Private Const SB_VERT As Integer = &H1
#End Region
#Region "dll calls"
'dll used to get the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash!
_
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function
'dll used to set the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash!
\_
Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
End Function
#End Region
Public Property HScrollPos() As Integer 'property to set or get the horisontal scrollbar value
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ) 'change txtscroll to the control you use. dont forget the .handle
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ, value, True) 'change txtscroll to the control you use. dont forget the .handle
End Set
End Property
Public Property VScrollPos() As Integer 'Property to set or get the Vertical scrollbar value
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_VERT) 'change txtscroll to the control you use. dont forget the .handle
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr