📄 用api操作文本框的文本.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "计算TextBox的行数(不使用TextBox的消息)"
ClientHeight = 3120
ClientLeft = 60
ClientTop = 345
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 3120
ScaleWidth = 5760
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "读取第21行改良版"
Height = 615
Left = 4320
TabIndex = 3
Top = 1800
Width = 1335
End
Begin VB.CommandButton Command2
Caption = "读取第21行"
Height = 495
Left = 4320
TabIndex = 2
Top = 960
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "计算行数"
Height = 495
Left = 4320
TabIndex = 1
Top = 120
Width = 1335
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "PMingLiU"
Size = 12
Charset = 136
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2775
Left = 240
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Text = "用API操作文本框的文本.frx":0000
Top = 120
Width = 3975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim LineCount As Long
LineCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, ByVal 0&)
MsgBox "行数=" & LineCount
End Sub
Private Sub Command2_Click()
Dim S As String, Length As Integer
Length = 80
S = String(Length, Chr(0))
RtlMoveMemory ByVal S, Length, 2
SendMessage Text1.hwnd, EM_GETLINE, 21, ByVal S
S = Left(S, InStr(S, Chr(0)) - 1)
MsgBox S, , "第21行"
End Sub
Private Sub Command3_Click()
Dim S As String, Length As Integer, pos As Long
pos = SendMessage(Text1.hwnd, EM_LINEINDEX, 21, ByVal 0&)
Length = SendMessage(Text1.hwnd, EM_LINELENGTH, pos, ByVal 0&)
S = String(Length, Chr(0))
RtlMoveMemory ByVal S, Length, 2
SendMessage Text1.hwnd, EM_GETLINE, 21, ByVal S
'S = Left(S, InStr(S, Chr(0)) - 1)
MsgBox S, , "第21行"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -