打印时文字环绕

时间:2015-03-20 22:05:15

标签: vb.net printing textwrapping

我正在努力确保PrintDocument上的字词和字符一直到页面边距并换行。目前它包含了相当大的差距:

红色是保证金。我希望文本一直到边距,如果超过,则将其包裹起来。

enter image description here

这是我的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

0 个答案:

没有答案