?
Solved

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

Posted on 2004-04-03
2
Medium Priority
?
435 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 2000 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

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…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 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