Solved

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

Posted on 2004-04-03
2
428 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Title # Comments Views Activity
Amazon S3 Images with .Net 3 61
VB.net/VSTO Excel Add-in 2 36
Difference between Highcharts and Mapbox 10 43
.NET universe documentation poster 2 18
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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