this example is printing lines of text to a printer

VB Code:
  1. Public Class PrintingExample
  2.     Private printFont As Font
  3.     Private streamToPrint As StreamReader
  4.     Private Shared filePath As String
  5.    
  6.     Public Sub New()
  7.         Printing()
  8.     End Sub    
  9.    
  10.     ' The PrintPage event is raised for each page to be printed.
  11.     Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs)
  12.         Dim linesPerPage As Single = 0
  13.         Dim yPos As Single = 0
  14.         Dim count As Integer = 0
  15.         Dim leftMargin As Single = ev.MarginBounds.Left
  16.         Dim topMargin As Single = ev.MarginBounds.Top
  17.         Dim line As String = Nothing
  18.        
  19.         ' Calculate the number of lines per page.
  20.         linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
  21.        
  22.         ' Iterate over the file, printing each line.
  23.         While count < linesPerPage
  24.             line = streamToPrint.ReadLine()
  25.             If line Is Nothing Then
  26.                 Exit While
  27.             End If
  28.             yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
  29.             ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
  30.                 yPos, New StringFormat())
  31.             count += 1
  32.         End While
  33.        
  34.         ' If more lines exist, print another page.
  35.         If Not (line Is Nothing) Then
  36.             ev.HasMorePages = True
  37.         Else
  38.             ev.HasMorePages = False
  39.         End If
  40.     End Sub
  41.      
  42.     ' Print the file.
  43.     Public Sub Printing()
  44.         Try
  45.             streamToPrint = New StreamReader(filePath)
  46.             Try
  47.                 printFont = New Font("Arial", 10)
  48.                 Dim pd As New PrintDocument()
  49.                 AddHandler pd.PrintPage, AddressOf pd_PrintPage
  50.                 ' Print the document.
  51.                 pd.Print()
  52.             Finally
  53.                 streamToPrint.Close()
  54.             End Try
  55.         Catch ex As Exception
  56.             MessageBox.Show(ex.Message)
  57.         End Try
  58.     End Sub 'Printing    
  59.    
  60.     ' This is the main entry point for the application.
  61.     Public Shared Sub Main()
  62.         Dim args() As String = System.Environment.GetCommandLineArgs()
  63.         Dim sampleName As String = args(0)
  64.         If args.Length <> 1 Then
  65.             Console.WriteLine("Usage: " & sampleName & " <file path>")
  66.             Return
  67.         End If
  68.         filePath = args(0)
  69.     End Sub
  70. End Class


Im curious, how can I determine the correct number of lines when I have different fonts on different lines? They ar enot all of the same size... An approximate value isn't safe I think....

kind regards
Henrik