Link to home
Start Free TrialLog in
Avatar of Azmodan
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.
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Hello

 Why not to use the SpinButton with Edit box

Best regards
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
Avatar of glass_cookie
glass_cookie

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 : )
Avatar of Azmodan

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
Avatar of Azmodan

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.
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.Caption)
  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