CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    14

    Printing and print preview Image problems

    I'm having problem with the print preview of image in a picturebox. The print preview dialog appears but with a plain white page only. Does anyone know what the problem is?

    Also how would i incorporate the page settings feature when i click on "print". So that instead of just printing the image straight away it would show the page settings dialog so I could choose the printer to print from or change the page settings.

    The code i'm using is below:

    Code:
        Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
            Try
                AddHandler PrintDocument1.PrintPage, AddressOf OnPrintPage
                PrintDocument1.Print()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    
        Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            e.Graphics.DrawImage(PictureBox1.Image, 0, 0)
        End Sub
    
        Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
            Try
                PrintPreviewDialog1.Document = PrintDocument1
                PrintPreviewDialog1.ShowDialog()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    Any help would be much appreciated!
    THANKS! =)

  2. #2
    Join Date
    May 2004
    Location
    Osijek
    Posts
    61

    Re: Printing and print preview Image problems

    Hi,

    You need to add handler to PrintPage event for print preview also. Maybe the best thing would be to move it to New or Form_Load.
    As for print settings, check PrintDialog control.

  3. #3
    Join Date
    Dec 2008
    Posts
    14

    Re: Printing and print preview Image problems

    thanks for your reply
    could you further explain "add handler to PrintPage event for print preview also" please?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Printing and print preview Image problems

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured