给你一个API操作纵SCROLL的例子自己研究一下就能搞定 ' Scrollbar direction
' All these constents can be found in WinUser.h
'
Const SBS_HORZ = 0
Const SBS_VERT = 1 ' Windows Messages
' All these constents can be found in WinUser.h
'
Const WM_VSCROLL = &H115
Const WM_HSCROLL = &H114
Const SB_THUMBPOSITION = 4 Public Enum eScrollAction
Jump = 0
Relitive = 1
End Enum Public Enum eScrollDirection
Vertical = 0
Horizontal = 1
End Enum ' Load in some data
'
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer For counter = 34 To 200
TextBox1.Text &= Chr(counter) & vbCrLf
Next
End Sub
' API Function: GetScrollPos
' Returns an integer of the position of the scrollbar
'
Private Declare Function GetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer) As Integer ' API Function: SetScrollPos
' Sets ONLY the scrollbar DOES NOT change the control object
'
Private Declare Function SetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByVal nPos As Integer, _
ByVal bRedraw As Boolean) As Integer ' API Function: PostMessageA
' Sends a message to a control (We are going to tell it to synch
' with the scrollbar)
'
Private Declare Function PostMessageA Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Boolean ' Sub: scrollControl
' Purpose: All functions to control the scroll are in here
'
Private Sub scrollControl(ByVal hWnd As IntPtr, ByVal Direction As eScrollDirection, _
ByVal Action As eScrollAction, ByVal Amount As Integer) Dim position As Integer ' What direction are we going
If Direction = eScrollDirection.Horizontal Then ' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_HORZ) + Amount
Else
position = Amount
End If ' Make it so
If (SetScrollPos(hWnd, SBS_HORZ, position, True) <> -1) Then
PostMessageA(hWnd, WM_HSCROLL, SB_THUMBPOSITION + &H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If Else ' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_VERT) + Amount
Else
position = Amount
End If ' Make it so
If (SetScrollPos(hWnd, SBS_VERT, position, True) <> -1) Then
PostMessageA(hWnd, WM_VSCROLL, SB_THUMBPOSITION + &H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If
End If
End Sub Private Sub Buttons(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click Select Case sender.text
Case "+"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, -5)
Case "-"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, 5)
Case "50"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 50)
Case "100"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 100)
End Select End Sub
' All these constents can be found in WinUser.h
'
Const SBS_HORZ = 0
Const SBS_VERT = 1 ' Windows Messages
' All these constents can be found in WinUser.h
'
Const WM_VSCROLL = &H115
Const WM_HSCROLL = &H114
Const SB_THUMBPOSITION = 4 Public Enum eScrollAction
Jump = 0
Relitive = 1
End Enum Public Enum eScrollDirection
Vertical = 0
Horizontal = 1
End Enum ' Load in some data
'
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer For counter = 34 To 200
TextBox1.Text &= Chr(counter) & vbCrLf
Next
End Sub
' API Function: GetScrollPos
' Returns an integer of the position of the scrollbar
'
Private Declare Function GetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer) As Integer ' API Function: SetScrollPos
' Sets ONLY the scrollbar DOES NOT change the control object
'
Private Declare Function SetScrollPos Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByVal nPos As Integer, _
ByVal bRedraw As Boolean) As Integer ' API Function: PostMessageA
' Sends a message to a control (We are going to tell it to synch
' with the scrollbar)
'
Private Declare Function PostMessageA Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Boolean ' Sub: scrollControl
' Purpose: All functions to control the scroll are in here
'
Private Sub scrollControl(ByVal hWnd As IntPtr, ByVal Direction As eScrollDirection, _
ByVal Action As eScrollAction, ByVal Amount As Integer) Dim position As Integer ' What direction are we going
If Direction = eScrollDirection.Horizontal Then ' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_HORZ) + Amount
Else
position = Amount
End If ' Make it so
If (SetScrollPos(hWnd, SBS_HORZ, position, True) <> -1) Then
PostMessageA(hWnd, WM_HSCROLL, SB_THUMBPOSITION + &H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If Else ' What action are we taking (Jumping or Relative)
If Action = eScrollAction.Relitive Then
position = GetScrollPos(hWnd, SBS_VERT) + Amount
Else
position = Amount
End If ' Make it so
If (SetScrollPos(hWnd, SBS_VERT, position, True) <> -1) Then
PostMessageA(hWnd, WM_VSCROLL, SB_THUMBPOSITION + &H10000 * position, Nothing)
Else
MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If
End If
End Sub Private Sub Buttons(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click Select Case sender.text
Case "+"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, -5)
Case "-"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Relitive, 5)
Case "50"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 50)
Case "100"
scrollControl(TextBox1.Handle, eScrollDirection.Vertical, eScrollAction.Jump, 100)
End Select End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货