i need some code to get the word under mouse in richtextbox after a search i found this code but it is good but dont working for first and last word after a newline in richtextbox anyone help me ???


Code:
Public Function GetWordUnderMouse(ByRef Rtf As System.Windows.Forms.RichTextBox, ByVal X As Integer, ByVal Y As Integer) As String
        On Error Resume Next
        Dim POINT As System.Drawing.Point = New System.Drawing.Point()
        Dim Pos As Integer, i As Integer, lStart As Integer, lEnd As Integer
        Dim lLen As Integer, sTxt As String, sChr As String
        '
        POINT.X = X
        POINT.Y = Y
        GetWordUnderMouse = vbNullString
        '
        With Rtf
            lLen = Len(.Text)
            sTxt = .Text
            Pos = Rtf.GetCharIndexFromPosition(POINT)
            If Pos > 0 Then
                For i = Pos To 1 Step -1
                    sChr = Mid(sTxt, i, 1)
                    If sChr = " " Or sChr = Chr(13) Or sChr = ControlChars.Lf Or i = 1 Then
                        'if the starting character is vbcrlf then
                        'we want to chop that off
                        If sChr = Chr(13) Then
                            lStart = (i + 2)
                        ElseIf sChr = " " Then
                            lStart = i
                        Else
                            lStart = (i + 2)
                        End If
                        Exit For
                    End If
                Next i
                For i = Pos To lLen
                    If Mid(sTxt, i, 1) = " " Or Mid(sTxt, i, 1) = Chr(13) Or i = lLen Then
                        lEnd = i + 1
                        Exit For
                    End If
                Next i
                If lEnd >= lStart Then
                    GetWordUnderMouse = Trim(Mid(sTxt, lStart, lEnd - lStart))
                End If
            End If
        End With
    End Function