Solved

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

Posted on 2011-02-16
2
880 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

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

10 Experts available now in Live!

Get 1:1 Help Now