[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Understanding some Print Code

Posted on 2006-05-02
5
Medium Priority
?
268 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:tony_813
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:MasterThai
ID: 16585437

its is used to figure out how many chars and lines can fit based on sizeMeasure
0
 
LVL 2

Expert Comment

by:MasterThai
ID: 16585445
and its being used right here
stringForPage = StringToPrint.Substring(0, numChars)
0
 
LVL 9

Author Comment

by:tony_813
ID: 16585535
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
 
LVL 2

Accepted Solution

by:
MasterThai earned 2000 total points
ID: 16585656
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
 
LVL 9

Author Comment

by:tony_813
ID: 16585800
Hello MasterThai...
    Thank you for your information..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question