Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long 试试这个
按每行字符数截取print就行
Private Sub Command1_Click() s = "123216545613214687一二三四五六七八九十12345678901234567890123456789012345678901234567890一二三四五六七八九十" With Picture1 For i = 1 To Len(s) If .TextWidth(Mid(s, 1, i)) > .Width Then Picture1.Print Mid(s, 1, i - 1) s = Mid(s, i): i = 1 End If Next End With If s <> "" Then Picture1.Print s End SubPrivate Sub Form_Load() Picture1.Width = 3000 End Sub
由于PICTUREBOX有边框,可以每行减少一个字 Option ExplicitPrivate Sub Form_Load() Command1_Click End Sub Private Sub Command1_Click() Dim s As String, i As Integer s = "123216545613214687一二三四五六七八九十12345678901234567890123456789012345678901234567890一二三四五六七八九十" With Picture1 For i = 1 To Len(s) If .TextWidth(Mid(s, 1, i + 1)) > .Width Then Picture1.Print Mid(s, 1, i - 1) s = Mid(s, i): i = 1 End If Next End With If s <> "" Then Picture1.Print s End Sub
Option ExplicitPrivate Sub Form_Load() Command1_Click End Sub Private Sub Command1_Click() Dim s As String, i As Integer s = "123216545613214687一二三四五六七八九十中国12345678901234567890123456789012345678901234567890一二三四五六七八九十" With Picture1 For i = 1 To Len(s) If .TextWidth(Mid(s, 1, i)) > .ScaleWidth Then Picture1.Print Mid(s, 1, i - 1) s = Mid(s, i): i = 1 End If Next End With If s <> "" Then Picture1.Print s End Sub
改成函数 Option ExplicitPrivate Sub Form_Load() Dim S As String S = "123216545613214687一二三四五六七八九十中国12345678901234567890123456789012345678901234567890一二三四五六七八九十" ShowTxtInPic Picture1, S End SubFunction ShowTxtInPic(Picture1, S) Dim I As Long With Picture1 For I = 1 To Len(S) If .TextWidth(Mid(S, 1, I)) > .ScaleWidth Then Picture1.Print Mid(S, 1, I - 1) S = Mid(S, I): I = 1 End If Next End With If S <> "" Then Picture1.Print S End Function
试试这个
Private Sub Command1_Click()
s = "123216545613214687一二三四五六七八九十12345678901234567890123456789012345678901234567890一二三四五六七八九十"
With Picture1
For i = 1 To Len(s)
If .TextWidth(Mid(s, 1, i)) > .Width Then
Picture1.Print Mid(s, 1, i - 1)
s = Mid(s, i): i = 1
End If
Next
End With
If s <> "" Then Picture1.Print s
End SubPrivate Sub Form_Load()
Picture1.Width = 3000
End Sub
Option ExplicitPrivate Sub Form_Load()
Command1_Click
End Sub
Private Sub Command1_Click()
Dim s As String, i As Integer
s = "123216545613214687一二三四五六七八九十12345678901234567890123456789012345678901234567890一二三四五六七八九十"
With Picture1
For i = 1 To Len(s)
If .TextWidth(Mid(s, 1, i + 1)) > .Width Then
Picture1.Print Mid(s, 1, i - 1)
s = Mid(s, i): i = 1
End If
Next
End With
If s <> "" Then Picture1.Print s
End Sub
Command1_Click
End Sub
Private Sub Command1_Click()
Dim s As String, i As Integer
s = "123216545613214687一二三四五六七八九十中国12345678901234567890123456789012345678901234567890一二三四五六七八九十"
With Picture1
For i = 1 To Len(s)
If .TextWidth(Mid(s, 1, i)) > .ScaleWidth Then
Picture1.Print Mid(s, 1, i - 1)
s = Mid(s, i): i = 1
End If
Next
End With
If s <> "" Then Picture1.Print s
End Sub
Option ExplicitPrivate Sub Form_Load()
Dim S As String
S = "123216545613214687一二三四五六七八九十中国12345678901234567890123456789012345678901234567890一二三四五六七八九十"
ShowTxtInPic Picture1, S
End SubFunction ShowTxtInPic(Picture1, S)
Dim I As Long
With Picture1
For I = 1 To Len(S)
If .TextWidth(Mid(S, 1, I)) > .ScaleWidth Then
Picture1.Print Mid(S, 1, I - 1)
S = Mid(S, I): I = 1
End If
Next
End With
If S <> "" Then Picture1.Print S
End Function