Click here to Skip to main content
13,090,178 members (50,760 online)
Rate this:
Please Sign up or sign in to vote.
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;
Posted 13-Jul-10 4:37am
Updated 13-Jul-10 9:50am
Rate this: bad
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.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

;P :laugh: :) :confused: X| :cool:

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 25 Feb 2011
Copyright © CodeProject, 1999-2017
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