以下是我在微软中文技术社区上跟网友的对话,来解答该问题:
SQS(
问
)
怎样获得
Textbox
的行数
(
包括自动换行
)
?先谢了!!!
Const
EM_GETLINECOUNT
=
&
HBA
Private
Declare
Function
SendMessageBynum
Lib
"
user32
"
Alias
"
SendMessageA
"
(
ByVal
hwnd
As
IntPtr,
ByVal
wMsg
As
Long
,
ByVal
wParam
As
Long
,
ByVal
lParam
As
Long
)
As
Long
Function
LineCount(
ByVal
txthwnd
As
Long
)
As
Long
On
Error
Resume
Next
LineCount
=
SendMessageBynum(
Me
.TextBox1.Handle, EM_GETLINECOUNT,
0
&
,
0
&
)
LineCount
=
Format
$(lineCount,
"
##,###
"
)
End Function
Private
Sub
Button1_Click(
ByVal
sender
As
System.Object,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
MessageBox.Show(LineCount(
Me
.TextBox1.Handle))
End Sub
以上代码运行不成功,谁能给出正确代码,谢谢
!
lgx1972(答):
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Const EM_GETLINECOUNT = &HBA
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim lineCount As Int32
On Error Resume Next
'得到,并在窗体的标题栏显示文本行数
lineCount = SendMessage(Me.TextBox1.Handle, EM_GETLINECOUNT, 0&, 0&)
Me.Text = lineCount.ToString("##,###")
SQS :
OK
了!
谢谢
lgx1972
的热心帮助!!!