用VB如何获取文本编辑框里面用鼠标选择了的区域(变兰部分)的行和列都是那几部分,获取行号

解决方案 »

  1.   

    思路:根据回车符的个数来确定行数Private Function GetCurRow(s As String, n As Long) As Long
        Dim sTmp As String
        sTmp = Left(s, n - 1)
        GetCurRow = Len(sTmp) - Len(Replace(sTmp, Chr(13), "")) + 1
    End FunctionPrivate Sub Command1_Click()
        MsgBox GetCurRow(Text1.Text, Text1.SelStart)'起始点行坐标
        MsgBox GetCurRow(Text1.Text, Text1.SelStart + Text1.SelLength)'结束点行坐标
    End Sub