如何打印其中包含选项卡的文本文件?

发布于 2024-11-02 19:38:59 字数 1091 浏览 6 评论 0原文

我正在尝试打印其中包含制表符的文本文件。问题是打印时不会显示这些选项卡。这是我的代码:

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
    Dim linesPerPage As Single = 0
    Dim yPos As Single = 0
    Dim count As Integer = 0
    Dim leftMargin As Single = ev.MarginBounds.Left
    Dim topMargin As Single = ev.MarginBounds.Top
    Dim line As String = Nothing

    ' Calculate the number of lines per page.
    linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

    ' Iterate over the file, printing each line.
    While count < linesPerPage
      line = streamToPrint.ReadLine()
      If line Is Nothing Then
        Exit While
      End If
      yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
      ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
        yPos, New StringFormat())
      count += 1
    End While

    ' If more lines exist, print another page.
    If Not (line Is Nothing) Then
      ev.HasMorePages = True
    Else
      ev.HasMorePages = False
    End If
End Sub

我需要做什么才能使其支持选项卡?

I am trying to print a text file with tab characters in it. The problem is that these tabs are not shown when printing. Here is my code:

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
    Dim linesPerPage As Single = 0
    Dim yPos As Single = 0
    Dim count As Integer = 0
    Dim leftMargin As Single = ev.MarginBounds.Left
    Dim topMargin As Single = ev.MarginBounds.Top
    Dim line As String = Nothing

    ' Calculate the number of lines per page.
    linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

    ' Iterate over the file, printing each line.
    While count < linesPerPage
      line = streamToPrint.ReadLine()
      If line Is Nothing Then
        Exit While
      End If
      yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
      ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
        yPos, New StringFormat())
      count += 1
    End While

    ' If more lines exist, print another page.
    If Not (line Is Nothing) Then
      ev.HasMorePages = True
    Else
      ev.HasMorePages = False
    End If
End Sub

What do I need to do to make it support tabs?

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

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

发布评论

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

评论(1

月依秋水 2024-11-09 19:38:59

您没有向我们提供问题的完整说明。另外,我假设streamToPrint变量是StreamReader类型。试试这个:

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
Dim myStringFormat As New StringFormat
Dim tabStops As Single() = {150.0F, 100.0F, 100.0F}
myStringFormat.SetTabStops(0.0F, tabStops)
'The above two line can be changed to the following:
'myStringFormat.SetTabStops(0.0F, {150.0F, 100.0F, 100.0F})
'your call
' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
  line = streamToPrint.ReadLine()
  If line Is Nothing Then
    Exit While
  End If
  yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
  ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
    yPos, myStringFormat)
  count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
  ev.HasMorePages = True
Else
  ev.HasMorePages = False
End If
End Sub

you did not give us a thourough specification of your problem.Also im assuming that the streamToPrint variable is of the StreamReader type.try this:

Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
Dim myStringFormat As New StringFormat
Dim tabStops As Single() = {150.0F, 100.0F, 100.0F}
myStringFormat.SetTabStops(0.0F, tabStops)
'The above two line can be changed to the following:
'myStringFormat.SetTabStops(0.0F, {150.0F, 100.0F, 100.0F})
'your call
' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
  line = streamToPrint.ReadLine()
  If line Is Nothing Then
    Exit While
  End If
  yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
  ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
    yPos, myStringFormat)
  count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
  ev.HasMorePages = True
Else
  ev.HasMorePages = False
End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文