使用制表符格式打印 WinForms 文本框

发布于 2024-09-06 03:52:25 字数 1089 浏览 3 评论 0原文

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

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

有人可以告诉我我做错了什么吗?

I have been working on some code that prints a textbox that lists contact information. When I try to print it, it doesn't print out the tabs that I used to format the text. Here is my code:

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

Can someone tell me what I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-09-13 03:52:26

如果你这样做会发生什么?

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。)

What happens if you do this?

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)

Does that change things? (Check my syntax - I don't typically do VB.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文