急求:VB 记事本中显示行列
用VB6.0做了一个记事本,需要在状态栏显示当前光标所在的行列richtextbox控件有没有可以获得当前行和列的属性或是方法?我如果想在状态栏显示行列的信息怎么办?...
用VB6.0做了一个记事本,需要在状态栏显示当前光标所在的行列
richtextbox控件有没有可以获得当前行和列的属性或是方法?
我如果想在状态栏显示行列的信息怎么办? 展开
richtextbox控件有没有可以获得当前行和列的属性或是方法?
我如果想在状态栏显示行列的信息怎么办? 展开
展开全部
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
如果窗体大小改变,调用
GetCaretPos
就可以了
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
如果窗体大小改变,调用
GetCaretPos
就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询