Text Wrapping when Printing RRS feed

  • Question

  • I'm trying to make sure that the words and characters on my PrintDocument go all the way to the page margins and wrap. At the moment it wraps with quite a gap:

    The red is the margin. I want the text to go all the way to the margin, if it exceeds, then wrap it.

    This is my PrintDocument code:

    Private Sub PrintDoc_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDoc.PrintPage
        Dim PrintFont As New Font(TheTextBox.FontFamily.ToString(), Convert.ToSingle(TheTextBox.FontSize))
        Dim charactersOnPage As Integer = TheTextBox.Text.Length
        Dim linesPerPage As Integer = TheTextBox.LineCount
        e.Graphics.DrawRectangle(Pens.Red, e.MarginBounds)
        e.Graphics.MeasureString(StringToPrint, PrintFont, e.MarginBounds.Size, StringFormat.GenericDefault, charactersOnPage, linesPerPage)
        e.Graphics.DrawString(StringToPrint, PrintFont, Brushes.Black, e.MarginBounds, StringFormat.GenericDefault)
        StringToPrint = StringToPrint.Substring(charactersOnPage)
        e.HasMorePages = StringToPrint.Length > 0
    End Sub

    MessageBox.Show("Hey You!")

    Saturday, March 21, 2015 12:13 AM