Printing Problem - How to get CORRECT bounds of page

joshuaand

Well-known member
Joined
Sep 2, 2003
Messages
45
Location
Australia
Hi,

Ok I am doing a print app, what I am trying to do is get the EXACT boundaries of the page, I want to print to the top left, 0,0, which is fine, but bottom right is a problem.

When I use ".VisibleClipBounds.Width" I get the correct with the first time, for the default printer, that is set to A4.

If I select another printer from the list, it gets a bit hairy.
If the printer is not set to A4, the ".VisibleClipBounds.Width" are wrong.

If I set the page size to A4 is still does not work, it seems to me that the page settings are the setttings for the default selected printer, even if you select another printer.

Here is some code:



Code:
Private Sub printBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printBtn.Click

Dim blah As New PrintDocument
blah.DocumentName = "mydoc.doc"

AddHandler blah.PrintPage, AddressOf PrintPage

Dim printDialog1 As New PrintDialog
printDialog1.Document = blah

If (printDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then

blah.PrinterSettings = printDialog1.PrinterSettings

blah.Print()
End If

End Sub

    Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)

        Dim myWidth as single = ev.Graphics.VisibleClipBounds.Width
        Dim myHeight as single = ev.Graphics.VisibleClipBounds.Height

         ev.Graphics.DrawImage(printLogoImage.Image, (myWidth - printLogoImage.Image.Width), (myHeight - printLogoImage.Image.Height), printLogoImage.Image.Width, printLogoImage.Image.Height)

    End Sub

When you do this:

Code:
        For i As Int16 = 0 To ev.PageSettings.PrinterSettings.PaperSizes.Count - 1
            If ev.PageSettings.PrinterSettings.PaperSizes(i).Kind = PaperKind.A4 Then
                ev.PageSettings.PaperSize = ev.PageSettings.PrinterSettings.PaperSizes(i)
                Exit For
            End If
        Next

it does not update "VisibleClipBounds"

Any suggestions???
 
Back
Top