Solved

Wrap text

Posted on 2002-05-09
7
167 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:Azmodan
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:mnasman
ID: 6998419
Hello

 Why not to use the SpinButton with Edit box

Best regards
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6998428
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
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6998520
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 : )
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Azmodan
ID: 6998648
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
0
 

Author Comment

by:Azmodan
ID: 6998840
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.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
ID: 6999266
Although this is not a perfect solution, you could take the text length and divide it by the output area length to determine how much can print, then print that portion and repeat for the remainder of the text.

Example:
Suppose that you have the text "This is a test of how to wrap text into a printable area." with font size Arial-12

Now let's say that your display area (form, picturebox, whatever) has a scalewidth of 150 pixels (2375 twips)

Using the display area (I'll use a form) get the textwidth and divide by the display width:

  Dim sglTextWidth As Single
  Dim sglFormWidth As Single
  Dim intRows As Integer
 
  sglTextWidth = Form1.TextWidth(Label1.Caption)'365
  sglFormWidth = Form1.ScaleWidth'150
  intRows = Int(sglTextWidth / sglFormWidth + 0.99)'3

From this, you can pull off the first block of characters (in this case 1/3 = 1/intRows) and print them.

  Form1.Print Left$(Label1.Caption, Len(Label1.Caption) / intRows)

And you can repeat this for each of the blocks.

--
The problems are:
1) Since the blocks will not actually fit exactly, the fraction will likely be slightly off.  In the above case, the actual fraction is 2.43 so taking 1/3 actually gives you less than you want.

2) This truncation will not take words into account.  To do that, you'll have to search backwards from the end of the substring to the previous word delimiter (space, punctuation, other(?))

If you'd like me to pursue this with you, let me know.

0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6999281
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
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now