?
Solved

Wrap text

Posted on 2002-05-09
7
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

777 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