如何将richtextbox垂直向上滚动一行,一行向下滚动到我的VB.NET代码中?

时间:2014-03-12 02:12:05

标签: vb.net richtextbox vertical-scroll

我想写一个代码,使我的Richtextbox1一行向上或一行向下垂直滚动。 我该怎么做? 谢谢大家。

1 个答案:

答案 0 :(得分:0)

Public Const WM_VSCROLL As Integer = &H115
Public Const SB_LINEDOWN As Integer = 1
Public Const SB_PAGEDOWN As Integer = 3
Public Const SB_LINEUP As Integer = 1
Public Const SB_PAGEUP As Integer = 2

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown

If e.KeyCode = Keys.Down Then
  e.Handled = True

  SendMessage(Me.RichTextBox1.Handle, WM_VSCROLL, SB_PAGEDOWN, 0)
ElseIf e.KeyCode = Keys.Up Then
  e.Handled = True

  SendMessage(Me.RichTextBox1.Handle, WM_VSCROLL, SB_PAGEUP, 0)
End If

 End Sub