Solved

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

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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