Solved

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

Posted on 2004-04-03
2
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

735 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