I'd like to print preview and print 3 tab pages from a windows form. Below is my code. I was able to get it to work if it's only one tab. but not 3 tab pages.
Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
Public Class Results
Dim bmp As System.Drawing.Bitmap
Dim bmp1 As System.Drawing.Bitmap
Dim bmp2 As System.Drawing.Bitmap
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.Document = PrintDocument1 'PrintDialog associate with PrintDocument.
If PrintDialog1.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.Document.DefaultPageSettings.Landscape = True
PrintPreviewDialog1.ShowDialog()
' Preview.
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
bmp = New Bitmap(Me.TabControl1.TabPages(0).Width, Me.TabControl1.TabPages(0).Height)
Me.TabControl1.TabPages(0).DrawToBitmap(bmp, Me.TabControl1.TabPages(0).ClientRectangle)
bmp1 = New Bitmap(Me.TabControl1.TabPages(1).Width, Me.TabControl1.TabPages(1).Height)
Me.TabControl1.TabPages(1).DrawToBitmap(bmp1, Me.TabControl1.TabPages(1).ClientRectangle)
bmp2 = New Bitmap(Me.TabControl1.TabPages(2).Width, Me.TabControl1.TabPages(2).Height)
Me.TabControl1.TabPages(2).DrawToBitmap(bmp2, Me.TabControl1.TabPages(2).ClientRectangle)
e.Graphics.DrawImage(bmp, 20, 20)
e.HasMorePages = True
e.Graphics.DrawImage(bmp1, 20, 20)
e.HasMorePages = True
e.Graphics.DrawImage(bmp2, 20, 20)
e.HasMorePages = False
'bmp.Dispose()
'bmp1.Dispose()
'bmp2.Dispose()
End Sub
End Class
Can anybody tell me what can I do to make it work? also if there's an entirely different way to do this please do share. Thanks