'add a vscrollbar(垂直滚动条) and a textbox with multiline=true and scrollbars=1
Option Explicit
Dim mybyte(1024) As Byte
Dim lines() As String, num As Integer
Private Sub Form_Load()
Dim i As Long
Open "c:\xxxx.txt" For Binary As #1
num = LOF(1) \ 1024
ReDim lines(num + 10)
For i = 0 To num
Get #1, i * 1024 + 1, mybyte
lines(i) = StrConv(mybyte, vbUnicode)
Next
Close #1
Text1.Height = Me.TextHeight("1") * 12
VScroll1.Move Text1.Left + Text1.Width, Text1.Top, VScroll1.Width, Text1.Height
VScroll1.Min = 0
VScroll1.Max = num
VScroll1.SmallChange = 1
VScroll1.Value = 0
End Sub
Private Sub vscroll1_Change()
Dim temp As String, i As Long
For i = VScroll1.Value To VScroll1.Value + 10
temp = temp & lines(i)
Next
Text1.Text = temp
End Sub
哎呀,没人知道吗 。 查中文google n 个礼拜始终找不到,今天只好找英文的,很快下面方法搞定。
Load Large File Into a Textbox
Q. I thought that most 64K limits were a thing of the past—notably that psuedo-32bit OS, Windows 9x. However, when I put a multiline textbox on a form (under NT4) and tried to load a large file into it, the file was truncated, and Len(txtBox.Text) returned 65,535. Can you provide an example of how to load more than 64K into a VB textbox?
A. Microsoft designed all the intrinsic controls to lowest-common-denominator specs. Because much of Windows 9x is still 16-bit, Microsoft made compromises "for your protection."
Under NT, the underlying edit class is fully 32-bit, but you must go entirely to the API if you want to exceed the built-in 64K limits. The most reliable method to load large amounts of text into a VB textbox is to use SendMessage with WM_SETTEXT (see Listing 3). The SetWindowText API wraps this message, but has the drawback that it doesn't return the proper result code when it fails under Windows 9x, should your code also find itself running there.
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
Private Declare Function SetWindowText Lib "user32" _
Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal _
lpString As String) As Long
Private Declare Function GetWindowTextLength Lib _
"user32" Alias "GetWindowTextLengthA" (ByVal hWnd As _
Long) As Long
Private Sub Form_Load()
Dim nRet As Long
Dim s As String
' Create string with >64K chars.
s = String(66000, "X")
Me.Show
' Try setting large amount of text.
nRet = SendMessage(Text1.hWnd, WM_SETTEXT, 0&, _
ByVal s)
Debug.Print "WM_SETTEXT: " & nRet
' See how much made it.
nRet = SendMessage(Text1.hWnd, WM_GETTEXTLENGTH, _
0&, ByVal 0&)
Debug.Print "WM_GETTEXTLENGTH: " & nRet
' This call doesn't report failure
' under Windows 9x!
nRet = SetWindowText(Text1.hWnd, s)
Debug.Print "SetWindowText: " & nRet
' Just for kicks...
nRet = GetWindowTextLength(Text1.hWnd)
Debug.Print "GetWindowTextLength: " & nRet
End Sub
Private Sub Form_Resize()
Text1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Listing 3 IEither of these two methods can load more than 64K of text into a standard VB textbox. Both work only in Windows NT/2000. Adding to the Windows 9x frustration is the failure of the SetWindowText API to report its own failure in that environment. Stick with SendMessage for the most reliable results, and insist on NT if you need full 32-bit capabilities.