Click here to Skip to main content
15,610,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 /

            // 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;
Updated 13-Jul-10 9:50am

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.
Share this answer
clore482 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.
;P :laugh: :) :confused: X| :cool:
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900