我正在努力确保PrintDocument
上的字词和字符一直到页面边距并换行。目前它包含了相当大的差距:
红色是保证金。我希望文本一直到边距,如果超过,则将其包裹起来。
这是我的PrintDocument
代码:
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