📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "文本框中光标的位置"
ClientHeight = 4185
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 4185
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 2175
Left = 360
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 360
Width = 3855
End
Begin VB.Label Label2
Caption = "Label2"
Height = 615
Left = 480
TabIndex = 2
Top = 3240
Width = 3255
End
Begin VB.Label Label1
Caption = "Label1"
Height = 375
Left = 480
TabIndex = 1
Top = 2640
Width = 3135
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const EM_GETSEL = &HB0
Const EM_LINEFROMCHAR = &HC9
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
Public Sub GetCaretPos(ByVal hwnd5 As Long, LineNo As Long, ColNo As Long)
Dim i As Long, j As Long
Dim lParam As Long, wParam As Long
Dim k As Long
i = SendMessage(hwnd5, EM_GETSEL, wParam, lParam)
'取得目前Caret所在前面有多少个byte。
j = i / 2 ^ 16
'取得前面有多少行。
LineNo = SendMessage(hwnd5, EM_LINEFROMCHAR, j, 0)
LineNo = LineNo + 1
k = SendMessage(hwnd5, EM_LINEINDEX, -1, 0)
'取得目前caret所在行前面有多少个byte。
ColNo = j - k + 1
End Sub
Private Sub showmouse()
Dim LineNo As Long, ColNo As Long
Call GetCaretPos(Text1.hwnd, LineNo, ColNo)
Label1.Caption = "光标在第" + CStr(LineNo) + "行"
Label2.Caption = "光标在第" + CStr(ColNo) + "字符"
End Sub
Private Sub Form_Load()
Dim k As String
k = "http://zmhh.mycool.net"
k = k & Chr(13) & Chr(10)
k = k & "mailto zmhh@263.net"
Text1.Text = k
showmouse
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
showmouse
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
showmouse
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -