使用选项卡格式打印WinForms TextBox

时间:2010-06-20 00:00:43

标签: vb.net winforms formatting textbox tabs

我一直致力于打印一个列出联系信息的文本框的代码。当我尝试打印它时,它不会打印出用于格式化文本的选项卡。这是我的代码:

Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) _
Handles prndoc.PrintPage

    Dim fnt As Font = resultTextBox.Font
    ev.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

    Dim area As SizeF = New SizeF(ev.MarginBounds.Width, ev.MarginBounds.Height)
    Dim lines, chars As Integer
    ev.Graphics.MeasureString(resultTextBox.Text.Substring(mStringPos), fnt, _
                              area, StringFormat.GenericTypographic, chars, _
                              lines)

    Dim rc As New RectangleF(ev.MarginBounds.Left, ev.MarginBounds.Top, _ 
                             ev.MarginBounds.Width, ev.MarginBounds.Height)
    ev.Graphics.DrawString(resultTextBox.Text.Substring(mStringPos, chars), _
                           fnt, Brushes.Black, rc, _
                           StringFormat.GenericTypographic)

    mStringPos += chars

    ev.HasMorePages = mStringPos < resultTextBox.Text.Length
End Sub

有人能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:0)

如果你这样做会怎么样?

Dim fmt as StringFormat
fmt = StringFormat.GenericTypographic
fmt.SetTabStops( -- put something here --  )
ev.Graphics.DrawString(resultTextBox.Text.Substring(mStringPos, chars), _
                           fnt, Brushes.Black, rc, _
                           fmt)

这改变了吗? (检查我的语法 - 我通常不做VB。)