Printing in VB.NET 2008 question

I can't figure out how to include data in the preview dialog.  I will get it to show, but it doesn't contain any data.  What changes do I need to make?  
Thanks in advance.
Agent909

Public Class frmPrint
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'PrintDocument1.Print()  ' this works, but I want to preview it first
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim printFont As Font
        Dim txtH As Integer = 0
        Dim txtW As Integer = 0
        Dim LMargin As Integer = 0
        Dim TMargin As Integer = 0
        Dim lineToPrint As String

        With PrintDocument1.DefaultPageSettings
            txtH = .PaperSize.Height - .Margins.Top - .Margins.Bottom
            txtW = .PaperSize.Width - .Margins.Left - .Margins.Right
            LMargin = PrintDocument1.DefaultPageSettings.Margins.Left
            TMargin = PrintDocument1.DefaultPageSettings.Margins.Top
        End With

        lineToPrint = "Yahoo!"
        printFont = New Font("Courier New", 10)
        Dim SF As New System.Drawing.StringFormat
        SF.LineAlignment = StringAlignment.Near

        e.Graphics.DrawString(lineToPrint, printFont, Brushes.Black, LMargin, TMargin, SF)
        e.HasMorePages = False

        PrintPreviewDialog1.ShowDialog()  'the dialog shows, but does not show "Yahoo!"
    End Sub
End Class
LVL 1
Agent909Asked:
Who is Participating?
 
käµfm³d 👽Commented:
According to http://msdn.microsoft.com/en-us/library/274tyhz7.aspx

Do something like the following:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
        Me.PrintPreviewDialog1.ShowDialog()
    End Sub

Open in new window

0
 
Agent909Author Commented:
Works great!  Thank you!
0
 
käµfm³d 👽Commented:
NP :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.