Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:54:02+00:00 2026-05-24T08:54:02+00:00

I am trying to print a text file with tab characters in it. The

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:54:03+00:00Added an answer on May 24, 2026 at 8:54 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract two blocks of code from a text file using Java
I am trying to print (to a text file) the fragmentation information give by
I'm trying to read in a text file of a bunch of words that
I'm trying to read a text file and then print out the integers in
This is a very strange issue. I'm trying to print a large text file,
I am trying to create a program that will read a text file and
The file that I've got to work with here is the result of an
I have a problem with my XML that I am trying to display on
I am trying to make a disorganized text file into a list suitable for
I'm trying to read a line of text from a text file and put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.