# Re: 请问:应如何将muliline 的Text 列印出来?

Posted by richard on December 09, 1998 at 09:50:44:

In Reply to: 请问:应如何将muliline 的Text 列印出来? posted by jan on December 08, 1998 at 17:20:39:

: 请问:应如何将muliline 的Text 列印出来?

: 我直接用 printer.print text1.text, 但是不成功

'以下放于模组内即可
Option Explicit
Const EM_GETLINE = &HC4
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
' 计算Textbox行数
'使用方法如下:
' Dim LineCnt As Long
' LineCnt = TextBoxLineCnt(Text1)
Public Function TextBoxLineCnt(ctl As TextBox) As Long
TextBoxLineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)
End Function
' 读取Textbox第N行的资料
' 使用方法如下:
' Dim str5 As String
' str5 = GetaLine(Text1, 1) '取得第二行的字串，以0为基底
Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String
Dim str5(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array
Dim str6 As String, i As Long
str5(0) = 255 '字串的前两个Byte存该字串的最大长度
str5(0) = 255
i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))
If i = 0 Then
GetaLine = ""
Else
str6 = StrConv(str5, vbUnicode)
GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)
End If
End Function
上面有API程式,你再建一个TEXTBOX控制项,将资料丢
进去,再一行一行印出即可.(先跟你说,这是个笨方法
,但一定可印)

Follow Ups: