日期:2014-05-20 浏览次数:21232 次
Public Class Form1
    Dim pt As Point
    Dim ptB As Point
    Dim b As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        b = False
    End Sub
    Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown
        If b <> True Then
            ptB.X = e.X
            ptB.Y = e.Y
        End If
        b = True
    End Sub
    Private Sub RichTextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseMove
        Dim i As Integer
        Dim j As Integer
        If b Then
            pt.X = e.X
            pt.Y = e.Y
            j = RichTextBox1.GetCharIndexFromPosition(ptB)
            i = RichTextBox1.GetCharIndexFromPosition(pt)
            Textbox1.Text = Math.Abs(i - j) '文本框内现实的数值就是个数
        End If
    End Sub
    Private Sub RichTextBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseUp
        b = False
    End Sub
End Class