here's my printing code:

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim printlinestring As String
        Dim horizontalPrintLocationSingle As Single
        Dim verticalPrintLocationSingle As Single
        Dim printfont As New Font("arial", 12)
        Dim lineheightsingle As Single = printfont.GetHeight
        horizontalPrintLocationSingle = e.MarginBounds.Left
        verticalPrintLocationSingle = e.MarginBounds.Top

        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()

        e.Graphics.DrawString("Caleb Tote", printfont, Brushes.Black, horizontalPrintLocationSingle, verticalPrintLocationSingle)
        verticalPrintLocationSingle += lineheightsingle * 2

        For listindexinteger As Integer = 0 To typeComboBox.Items.Count - 1
            printlinestring = typeComboBox.Items(listindexinteger)
            e.Graphics.DrawString(printlinestring, printfont, Brushes.Black, horizontalPrintLocationSingle, verticalPrintLocationSingle)
            verticalPrintLocationSingle += lineheightsingle
        Next
    End Sub

I get an error at run time that says InvalidOperationException was unhandled by user code at this line:

PrintPreviewDialog1.ShowDialog()

Any help?
Thanks!

nevermind, fixed it.
I had put

PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()

in PrintDocument1_PrintPage instead of printButton_Click.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.