计算文本框中输入文本的行函数数可以使用SendMessage返回,当一行文字发生环绕时,它将被当作新的一行,而被非简单的计算文本中的换行符个数。
把以下API函数的声明添入模块文件的general declarations区域。
Option Explicit
Public Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Const EM_GETLINECOUNT = &HBA
Form Code
Sub Text1_Change()
Dim lineCount as Long
On Local Error Resume Next
'得到/显示文本行数
lineCount = SendMessageLong(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
Label1.Caption = Format(lineCount, "##,###")
End Sub
注释:为了使本程序成功,请在设计阶段把文本框的Multiline属性设为True。
本文地址:http://com.8s8s.com/it/it43593.htm