Understanding some Print Code

Hello Everyone,
    First.. before I begin.. this is not homework...
    I am trying to learn Visual Baisc on my own...
   
    I was reading a book Visual Basic 2005 Step by Step
    I was going over the following code... and I was trying to determine what the following line is being used for:

       e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)

    Per the helps files from Visual Basic it tells me the following:

      Measures the specified string when drawn with the specified Font and formatted with the specified StringFormat.

   However, I really dont understand how that line is being used within the code... I dont see the returned item being
   applied to any part of the code?

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
        ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim numChars As Integer
        Dim numLines As Integer
        Dim stringForPage As String
        Dim strFormat As New StringFormat

        Dim rectDraw As New Rectangle(e.MarginBounds.Left, e.MarginBounds.Top, _
            e.MarginBounds.Width, e.MarginBounds.Height)

        Dim sizeMeasure As New SizeF(e.MarginBounds.Width, _
            e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))

        strFormat.Trimming = StringTrimming.Word

        e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)

        stringForPage = StringToPrint.Substring(0, numChars)

        e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat)

        If numChars < StringToPrint.Length Then
            StringToPrint = StringToPrint.Substring(numChars)
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            StringToPrint = RichTextBox1.Text
        End If
    End Sub

Any assitance would be appricated

thank you
tony_813
LVL 9
tony_813Asked:
Who is Participating?
 
MasterThaiCommented:
its basically a wrapper to that sets and handles the details of the string being printed...

say you have a string that is 400 charcters long with no spaces... this will make the printed page look correct along with handling other things to like font details
0
 
MasterThaiCommented:

its is used to figure out how many chars and lines can fit based on sizeMeasure
0
 
MasterThaiCommented:
and its being used right here
stringForPage = StringToPrint.Substring(0, numChars)
0
 
tony_813Author Commented:
Hello MasterThai,  thank you for your quick response... sorry to ask more about this...

   How is the result of:

    e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)

  Being used in:

    stringForPage = StringToPrint.Substring(0, numChars)

  When the result of: e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, strFormat, numChars, numLines)
  was never assigned to a variable to be used in: stringForPage = StringToPrint.Substring(0, numChars)??

thnx
tony_813
0
 
tony_813Author Commented:
Hello MasterThai...
    Thank you for your information..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.