Solved

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

Posted on 2004-04-03
2
429 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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