Solved

Print Preview problem, only 4 lines per page!! Help!!!

Posted on 2004-04-03
2
422 Views
Last Modified: 2007-12-19
Hi, all. Can you tell me what is wrong in below code??? Print preview only has 4 lines per page, Thank you

Private Sub ThePrintDocument_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs) Handles ThePrintDocument.PrintPage
        Dim linesPerPage As Single = 0
        Dim yPosition 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 printFont As Font = frm.AxCodeMax.Font()
        Dim myBrush As New SolidBrush(Color.Black)

        ' Work out the number of lines per page, using the MarginBounds.
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

        ' Iterate over the string using the StringReader, printing each line.
        line = myReader.ReadLine()
        While count < linesPerPage And (Nothing <> line)

            ' calculate the next line position based on
            ' the height of the font according to the printing device
            yPosition = (topMargin + (count * printFont.GetHeight(ev.Graphics)))

            ' draw the next line in the codemax edit control
            ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, New StringFormat())
            count += 1
            line = myReader.ReadLine()
        End While

        ' If there are more lines, print another page.
        If Not (line Is Nothing) Then
            ev.HasMorePages = True
        Else
            ev.HasMorePages = False
        End If
        myBrush.Dispose()
    End Sub 'ThePrintDocument_PrintPage
0
Comment
Question by:davidlam8888
2 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10750669
Private Sub mnuPrnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click

        Try
            AddHandler PrintDocument1.PrintPage, AddressOf Me.PrintDocument1_PrintPage
            printPreviewDialog1.StartPosition = FormStartPosition.CenterParent
            printPreviewDialog1.ShowInTaskbar = False
            printPreviewDialog1.Document = Me.PrintDocument1
            printPreviewDialog1.ShowDialog() '
        Catch exp As Exception
            System.Console.WriteLine(exp.Message.ToString())
        End Try
    End Sub


http://www.devcity.net/forums/topic.asp?tid=61430
0
 
LVL 12

Accepted Solution

by:
farsight earned 500 total points
ID: 10754079
I suspect that the _units_ for the numerator and denominator in this line are different.  I can't tell for sure, because printFont comes from AxCodeMax, which I'll unfamiliar with.

>          linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

Set a breakpoint on this line and the line after it.  Either introduce new variables for the numerator and denominator that you can see in the debugger, or use the command windows to view the values.

[in command window]
? ev.MarginBounds.Height
? printFont.GetHeight(ev.Graphics)
? linesPerPage

Determine what the units are for each (numerator and denominator).  Is it twips, pixels, inches, user-defined-units, or something else? Then introduce a conversion factor to fix it up.  Multiply (or divide) by the conversion factor.
Something like:    linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) * TwipsPerPixelVertical

If you don't get clear results, please tell us what values you get for these items.

---
[style issue]
You used "(Nothing <> line)" at one place, and "Not (line Is Nothing)" at another place.  I prefer the latter, "Not (line Is Nothing)", but in any case, try to stay consistent.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now