Solved

How do I make text wrap inside a rectangle placed on a printDocument?

Posted on 2011-02-16
2
906 Views
Last Modified: 2013-12-17
I have a printDocument which I'd like to add several rectangles to.  Each rectangle will have text in it; this text needs to wrap.  NOTE: Not only do I want the text to wrap, I need it to be 'bottom justified,' meaning, the text wraps and always sits on the bottom of the rectangle.  Please help!
0
Comment
Question by:David L. Hansen
[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 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34909438
Use a StringFormat with LineAlignment set to Far.  Pass the Rectangle and that StringFormat to DrawString.

Here's a simplified example using the Paint() event of the Form:
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim txt As String = "This is the text to wrap and bottom justify in the rectangle contained in the print document"

        Dim rc As New Rectangle(100, 75, 200, 300)
        e.Graphics.DrawRectangle(Pens.Black, rc)

        Dim sf As New StringFormat()
        sf.LineAlignment = StringAlignment.Far
        e.Graphics.DrawString(txt, Me.Font, Brushes.Black, rc, sf)
    End Sub

Open in new window

0
 
LVL 15

Author Comment

by:David L. Hansen
ID: 34909719
Although I'm not using a form, the guts of the code you posted is perfect.  Thank you!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS 2017 18 109
Access Schema 6 45
ASP.NET on IIS website not sending PDF file anymore ? [IzillaFramework Cognition] 6 54
Broken .resx file generating errors 18 27
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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