Solved

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

Posted on 2011-02-16
2
890 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
2 Comments
 
LVL 85

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Alert on Server memory 2 21
Following an example - Why do I need to click Save button twice? 3 25
Write to a printer using vb.net 9 25
VB.NET 2008 - SQL Timeout 9 24
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 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