vb statusbar怎么显示当前鼠标所在文本行数
vbstatusbar里面做了一个状态栏,还有一个richtextbox。要怎么做才能把richtextbox里面的鼠标所在文本行数显示到假设是statusbar1.pa...
vb statusbar里面做了一个状态栏,还有一个richtextbox。要怎么做才能把richtextbox里面的鼠标所在文本行数显示到假设是statusbar1.panels(1)里面去
还有一个就是怎么计算光标所选定的文本的字数,也假设把它放到statusbar1.panels(2)里面
高手多多指教
好的定加分!!!! 展开
还有一个就是怎么计算光标所选定的文本的字数,也假设把它放到statusbar1.panels(2)里面
高手多多指教
好的定加分!!!! 展开
2个回答
展开全部
VB 6.0 获取 richtextbox当前行和列
Private Const EM_GETSEL = &HB0
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub GetCaretPos(ByVal TextHwnd As Long, LineNo As Long, ColNo As Long)
Dim i As Long
Dim j As Long
Dim k As Long
Dim lParam As Long
Dim wParam As Long
i = SendMessage(TextHwnd, EM_GETSEL, wParam, lParam)
j = i / 2 ^ 16
LineNo = SendMessage(TextHwnd, EM_LINEFROMCHAR, j, 0)
LineNo = LineNo + 1
k = SendMessage(TextHwnd, EM_LINEINDEX, -1, 0)
ColNo = j - k + 1
End Sub
Private Sub RichTextBox1_SelChange()
Dim LineNo As Long
Dim ColNo As Long
GetCaretPos RichTextBox1.hwnd, LineNo, ColNo
Label1.Caption = LineNo '行 状态条代码写在这里
Label2.Caption = ColNo '列
End Sub
RichTextBox 属性 SelLength 的值 就是选定的文本的字数
Private Const EM_GETSEL = &HB0
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub GetCaretPos(ByVal TextHwnd As Long, LineNo As Long, ColNo As Long)
Dim i As Long
Dim j As Long
Dim k As Long
Dim lParam As Long
Dim wParam As Long
i = SendMessage(TextHwnd, EM_GETSEL, wParam, lParam)
j = i / 2 ^ 16
LineNo = SendMessage(TextHwnd, EM_LINEFROMCHAR, j, 0)
LineNo = LineNo + 1
k = SendMessage(TextHwnd, EM_LINEINDEX, -1, 0)
ColNo = j - k + 1
End Sub
Private Sub RichTextBox1_SelChange()
Dim LineNo As Long
Dim ColNo As Long
GetCaretPos RichTextBox1.hwnd, LineNo, ColNo
Label1.Caption = LineNo '行 状态条代码写在这里
Label2.Caption = ColNo '列
End Sub
RichTextBox 属性 SelLength 的值 就是选定的文本的字数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const EM_GETFIRSTVISIBLELINE = &HCE
Const EM_LINEFROMCHAR = &HC9
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Public Function GetLineFromChar(txtBox As RichTextBox, CharPos As Long) As Long
GetLineFromChar = SendMessage(txtBox.hwnd, EM_LINEFROMCHAR, CharPos, 0&)
End Function
StatusBar1.Panels(1).Text = GetLineFromChar(RichTextBox1, RichTextBox1.SelStart) + 1
StatusBar1.Panels(2).Text = RichTextBox1.SelLength
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const EM_GETFIRSTVISIBLELINE = &HCE
Const EM_LINEFROMCHAR = &HC9
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Public Function GetLineFromChar(txtBox As RichTextBox, CharPos As Long) As Long
GetLineFromChar = SendMessage(txtBox.hwnd, EM_LINEFROMCHAR, CharPos, 0&)
End Function
StatusBar1.Panels(1).Text = GetLineFromChar(RichTextBox1, RichTextBox1.SelStart) + 1
StatusBar1.Panels(2).Text = RichTextBox1.SelLength
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询