VB.NET RichTextBox鼠标右键点击后光标移动至点击的位置

Public Class Form1
     _
          Private Shared Function mouse_event(dwFlags As Integer, dx As Integer, dy As Integer, cButtons As Integer, dwExtraInfo As Integer) As Integer
    End Function

    Const MOUSEEVENTF_MOVE As Integer = &H1
    Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8
    Const MOUSEEVENTF_RIGHTUP As Integer = &H10
    Const MOUSEEVENTF_MIDDLEDOWN As Integer = &H20
    Const MOUSEEVENTF_MIDDLEUP As Integer = &H40
    Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000

    Private Sub 内容_MouseDown(sender As Object, e As MouseEventArgs) Handles 内容.MouseDown
        If DirectCast(sender, RichTextBox).SelectionLength = 0 Then
            If e.Button = MouseButtons.Right Then
                mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, e.X, e.Y, 0, 0)
                Application.DoEvents()
            End If
        End If
    End Sub
End Class

"内容"为 richtextbox的Name

你可能感兴趣的:(vb.net)