怎样才能知道TextBox中有多少行了?

xingming_sun 2001-12-05 11:32:05
我做了一个关于自动处理方面的小程序,用TextBox控件来显示程序运行过程
中出现的种种提示信息。我担心TextBox不能显示太多的内容,因而打算
在TextBox显示50行的时候清空TextBox,但是如何才能得知TextBox已经
有50行了呢?拜托各位了,谢谢。

或则有其它的解决方法,烦请告知,不胜感激。
...全文
176 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangzhaoyu 2001-12-05
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim txtLine As Long
txtLine = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, ByVal 0&)
Debug.Print txtLine
End Sub

DeityFox 2001-12-05
  • 打赏
  • 举报
回复
在TextBox中如何得知Caret所在位置

原始来源:cww

'在form中放一个textBox两个label
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)
j = i / 2 ^ 16 '取得目前Caret所在前面有多少个byte
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 Form_Load()
Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)
Label1.Caption = LineNo
Label2.Caption = ColNo

End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)
Label1.Caption = LineNo
Label2.Caption = ColNo

End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim LineNo As Long, ColNo As Long

Call GetCaretPos(Text1.hwnd, LineNo, ColNo)
Label1.Caption = LineNo
Label2.Caption = ColNo

End Sub
DeityFox 2001-12-05
  • 打赏
  • 举报
回复
在TextBox中如何得知所有的行数

原始来源:cww

呼叫方式

Dim LineCnt as Long

LineCnt = TextBoxLineCnt(Text1)


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 Const EM_GETLINECOUNT = &HBA

Public Function TextBoxLineCnt(ctl As TextBox) As Long
TextBoxLineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)
End Function

leonkim 2001-12-05
  • 打赏
  • 举报
回复
你可以先算一算TextBox中每行多少个字符,再*50,当LEN(TEXT1)大于这个值时,text1=""
就可以了,最好要区分一个中英文字符。
dapha 2001-12-05
  • 打赏
  • 举报
回复
有一个笨方法就是查找vbcrlf,方法可行如果数据多的话速度较慢
tipstudio_zsp 2001-12-05
  • 打赏
  • 举报
回复
有一个不用api的办法
你查找一下字符串里面有多少个换行符即可
cloud_soft 2001-12-05
  • 打赏
  • 举报
回复
sendmessage, 晚了
相关推荐
发帖
VB基础类

7681

社区成员

VB 基础类
社区管理员
  • VB基础类社区
加入社区
帖子事件
创建了帖子
2001-12-05 11:32
社区公告
暂无公告