?
Solved

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

Posted on 2011-02-16
2
Medium Priority
?
918 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 2000 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

801 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