Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET printing string
Right now, I am currently reading in a text file and wrapping the text that is too big for a page. I currently have tabstops set up, but when the text is wrapped, it begins on the left margin again instead of the indent. How would I fix this? Thanks.
 
EDIT: I have tried messing with the left margin in the rectangle's parameters, but it just shifts the entire text entry over, not just the wrapped lines following the parent line.
 
// Calculate the number of lines per page.
            linesPerPage = ev.MarginBounds.Height /
                printFont.GetHeight(ev.Graphics);
 
            // Print each line of the file.
            while (lineNumber < linesPerPage &&
                ((line = streamToPrint.ReadLine()) != null))
            {
                StringFormat sf = StringFormat.GenericTypographic;
                sf.Alignment = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Near;
                sf.FormatFlags = StringFormatFlags.LineLimit;
                sf.Trimming = StringTrimming.Word;
                sf.SetTabStops(0.0f, tabStops);
 
                //Get dimensions of string
                actual = ev.Graphics.MeasureString(line, printFont,
                 new SizeF(ev.MarginBounds.Size.Width,
                      ev.MarginBounds.Size.Height), sf, out charCount, out lineCount);
 

                ev.Graphics.DrawString(line, printFont, Brushes.Black,
                new RectangleF(leftMargin, yPos, ev.MarginBounds.Size.Width,
                ev.MarginBounds.Size.Height), sf);
 
                //Add rectangle height to Y position
                yPos += actual.Height;
Posted 13-Jul-10 5:37am
Edited 13-Jul-10 10:50am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to start with a tab to create an indent that is further in than the margin. There's no way for the first line to stick further left than the rest, without you calculating how much text fits on a line and then putting the rest after the first line in a new rectangle.
  Permalink  
Comments
clore482 at 13-Jul-10 16:13pm
   
Right now, tabbed lines are tabbed accurately with the use of my tabstop as long as they do not wrap. However, when text wraps, the lines following the initial "parent" line are aligned with the left margin instead of the indention of the "parent" line.
 
In this sense, I am starting with a tab when needed.
 
I've thought about calculating how much text fits on a line and readjusts the line, but that defeats the purpose of the string format wrapping.
 
There isn't any easy way around this, is there?
 
Thanks for the help; I appreciate it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Poke tongue | ;-P Laugh | :laugh: Smile | :) Confused | :confused: Dead | X| Cool | :cool:
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 25 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100