Private Sub Command1_Click()
Text1.Text = GetMaxVisibleStr(Text1, Text2.Text)
Debug.Print Text1.Text
End Sub
Public Function GetMaxVisibleStr(TheText As TextBox, _
TheStr As String) As String
Dim i As Long
With Label1
.BorderStyle = TheText.BorderStyle
.Font = TheText.Font
For i = 1 To Len(TheStr)
.Caption = Left(TheStr, i)
If .Width > TheText.Width Then
GetMaxVisibleStr = Left(TheStr, i - 1)
Exit Function
End If
Next i
End With
Private Sub Command1_Click()
Text1.Text = GetMaxVisibleStr(Text1, Text2.Text)
Debug.Print Text1.Text
End Sub
Public Function GetMaxVisibleStr(TheText As TextBox, _
TheStr As String) As String
Dim i As Long
Label1.BorderStyle = Text1.BorderStyle
For i = 1 To Len(TheStr)
With Label1
.Caption = Left(TheStr, i)
If .Width > TheText.Width Then
GetMaxVisibleStr = Left(TheStr, i - 1)
Exit Function
End If
End With
Next i
1.如何把一个文本文件分别装入几个textbox中(文字要连续且每个textbox都要装满。)?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
在下面的基础上改吧,问题2和这个一样
Private Sub cmdLoad_Click()
Dim nLen As Long
Dim nTotal As Long
Dim cChar As String * 1
Dim i As Integer
Dim j As Integer
nLen = 0
nTotal = 0
Open "c:\test.txt" For Input As #1
For i = 0 To 100
nLen = GetTextboxSize(Text1(i))
For j = 0 To nLen - 1
If EOF(1) Then
Close #1
Exit Sub
Else
Input #1, cChar
Text1(i).Text = Text1(i).Text & cChar
nTotal = nTotal + 1
End If
Next
Next
End Sub
Private Function GetTextboxSize(txt As TextBox) As Long
Dim nLines As Integer
Dim nWords As Integer