Azmodan
asked on
Wrap text
I need to print wraped text. How do I do that? Because a hidden textbox cannot be BitBlted...
I don't want to evaluate the length character by character.
I don't want to evaluate the length character by character.
oppppppps, plz ignore my last comment
I was opening two questions at the same time, so I post my comments in the wrong question
i'm so sorry
I was opening two questions at the same time, so I post my comments in the wrong question
i'm so sorry
Hi!
How about this (this is what I normally do)...
Plac the textbox on an empty form with both the textbox and form set to borderstyle = none and their backcolor, white.
Remove all scrollbars on the textbox if any. Then, use a mdi form to load your white form (which must be set to mdichild = true. Sie your form to how much of the form that you want to print on paper.
After all these has been done, simply use this code:
WhiteForm.PrintForm 'Or whatever is the name of your form)
This will print whatever that's displayed on the form.
That's it!
glass cookie : )
How about this (this is what I normally do)...
Plac the textbox on an empty form with both the textbox and form set to borderstyle = none and their backcolor, white.
Remove all scrollbars on the textbox if any. Then, use a mdi form to load your white form (which must be set to mdichild = true. Sie your form to how much of the form that you want to print on paper.
After all these has been done, simply use this code:
WhiteForm.PrintForm 'Or whatever is the name of your form)
This will print whatever that's displayed on the form.
That's it!
glass cookie : )
ASKER
i thought of a solution
I put the text in a textbox multiline, let it wrap the text, and than read with API line by line from the textbox
I put the text in a textbox multiline, let it wrap the text, and than read with API line by line from the textbox
ASKER
But i can't get the API to work
res = SendMessageLong(Text1.hwnd , EM_GETLINE, 1, VarPtr(buff))
it crashes every time.
In the help it says that the first word of the buff must be the maximum length of the text read.
res = SendMessageLong(Text1.hwnd
it crashes every time.
In the help it says that the first word of the buff must be the maximum length of the text read.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Anyway, here's the simple wrapping code, without any consideration for "words". Add a label with the text to print (in your case, replace Label1.Caption with your hidden textbox's name and text property) Also, replace Form1 with the name of your desired output area. I'm initiating the process with a button (Command1) click.
Private Sub Command1_Click()
Dim sglTextWidth As Single
Dim sglFormWidth As Single
Dim sglLineLength As Single
Dim intRows As Integer
Dim strText As String
sglTextWidth = Form1.TextWidth(Label1.Cap tion)
sglFormWidth = Form1.ScaleWidth
sglLineLength = sglTextWidth / sglFormWidth
intRows = Int(sglLineLength + 0.99)
strText = Label1.Caption
While strText <> vbNullString
Form1.Print Left$(strText, Len(Label1.Caption) / sglLineLength)
strText = Mid$(strText, Len(Label1.Caption) / sglLineLength + 1)
Wend
End Sub
Private Sub Command1_Click()
Dim sglTextWidth As Single
Dim sglFormWidth As Single
Dim sglLineLength As Single
Dim intRows As Integer
Dim strText As String
sglTextWidth = Form1.TextWidth(Label1.Cap
sglFormWidth = Form1.ScaleWidth
sglLineLength = sglTextWidth / sglFormWidth
intRows = Int(sglLineLength + 0.99)
strText = Label1.Caption
While strText <> vbNullString
Form1.Print Left$(strText, Len(Label1.Caption) / sglLineLength)
strText = Mid$(strText, Len(Label1.Caption) / sglLineLength + 1)
Wend
End Sub
Why not to use the SpinButton with Edit box
Best regards