Solved

Wrap text

Posted on 2002-05-09
7
168 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:Mohammed Nasman
ID: 6998419
Hello

 Why not to use the SpinButton with Edit box

Best regards
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

25 Experts available now in Live!

Get 1:1 Help Now