Ik heb een WindowsForm met meerdere Tabpages(12) gebouwd. Graag zou ik deze Tabpages (ieder op een afzonderlijke PDF pagina) rapporteren. Dit alles via een Printer(Settings) Dialoog-->Print to PDF. (mag ook via andere methode bijv. tabpages direct gegenereerd in pdf).
Door op Button1 te klikken wordt deze procedure in gang gezet. Alles werkt en alle tabpagina's worden op een afzonderlijke PDF pagina gerapporteerd. Maar als de 2e keer op Button1 wordt geklikt, verschijnt er na de Print to PDF dialoog alleen 1 blanco PDF-pagina. Niet de 12 tabpages met controls/objecten die iedere tabpage bevat.
De onderstaande code is misschien wat omslachtig/kan korter, maar dit is de enige manier dat ik het werkend krijg (althans, eenmalig, na 2e keer klikken op Button1 werkt het dus niet meer-->alleen blanco PDF)
Iemand een idee wat ik verkeerd doe? Graag hulp
Door op Button1 te klikken wordt deze procedure in gang gezet. Alles werkt en alle tabpagina's worden op een afzonderlijke PDF pagina gerapporteerd. Maar als de 2e keer op Button1 wordt geklikt, verschijnt er na de Print to PDF dialoog alleen 1 blanco PDF-pagina. Niet de 12 tabpages met controls/objecten die iedere tabpage bevat.
De onderstaande code is misschien wat omslachtig/kan korter, maar dit is de enige manier dat ik het werkend krijg (althans, eenmalig, na 2e keer klikken op Button1 werkt het dus niet meer-->alleen blanco PDF)
Iemand een idee wat ik verkeerd doe? Graag hulp
Code:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
PrintDocument1.Print()
End If
End Sub
Code:
Public Class Form1
Dim PageNumber As Integer = 0
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Select Case PageNumber
Case 0
Me.TabControl1.SelectedTab = TabPage1
Dim TabBitmap As New Bitmap(TabControl1.TabPages(0).Width, TabControl1.TabPages(0).Height)
TabControl1.TabPages(0).DrawToBitmap(TabBitmap, New Rectangle(Point.Empty, TabBitmap.Size))
e.Graphics.DrawImage(TabBitmap, 50, 50, 1000, 500)
If Me.TextBox2.Text = "1" Then
e.HasMorePages = True
End If
Case 1
If Me.TextBox2.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage2
Dim TabBitmap1 As New Bitmap(TabControl1.TabPages(1).Width, TabControl1.TabPages(1).Height)
TabControl1.TabPages(1).DrawToBitmap(TabBitmap1, New Rectangle(Point.Empty, TabBitmap1.Size))
e.Graphics.DrawImage(TabBitmap1, 50, 400, 1000, 500)
If Me.TextBox3.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 2
If Me.TextBox3.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage3
Dim TabBitmap2 As New Bitmap(TabControl1.TabPages(2).Width, TabControl1.TabPages(2).Height)
TabControl1.TabPages(2).DrawToBitmap(TabBitmap2, New Rectangle(Point.Empty, TabBitmap2.Size))
e.Graphics.DrawImage(TabBitmap2, 50, 400, 1000, 500)
If Me.TextBox4.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 3
If Me.TextBox4.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage4
Dim TabBitmap3 As New Bitmap(TabControl1.TabPages(3).Width, TabControl1.TabPages(3).Height)
TabControl1.TabPages(3).DrawToBitmap(TabBitmap3, New Rectangle(Point.Empty, TabBitmap3.Size))
e.Graphics.DrawImage(TabBitmap3, 50, 400, 1000, 500)
If Me.TextBox5.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 4
If Me.TextBox5.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage5
Dim TabBitmap4 As New Bitmap(TabControl1.TabPages(4).Width, TabControl1.TabPages(4).Height)
TabControl1.TabPages(4).DrawToBitmap(TabBitmap4, New Rectangle(Point.Empty, TabBitmap4.Size))
e.Graphics.DrawImage(TabBitmap4, 50, 400, 1000, 500)
If Me.TextBox6.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 5
If Me.TextBox6.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage6
Dim TabBitmap5 As New Bitmap(TabControl1.TabPages(5).Width, TabControl1.TabPages(5).Height)
TabControl1.TabPages(5).DrawToBitmap(TabBitmap5, New Rectangle(Point.Empty, TabBitmap5.Size))
e.Graphics.DrawImage(TabBitmap5, 50, 400, 1000, 500)
If Me.TextBox7.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 6
If Me.TextBox7.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage7
Dim TabBitmap6 As New Bitmap(TabControl1.TabPages(6).Width, TabControl1.TabPages(6).Height)
TabControl1.TabPages(6).DrawToBitmap(TabBitmap6, New Rectangle(Point.Empty, TabBitmap6.Size))
e.Graphics.DrawImage(TabBitmap6, 50, 400, 1000, 500)
If Me.TextBox8.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 7
If Me.TextBox8.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage8
Dim TabBitmap7 As New Bitmap(TabControl1.TabPages(7).Width, TabControl1.TabPages(7).Height)
TabControl1.TabPages(7).DrawToBitmap(TabBitmap7, New Rectangle(Point.Empty, TabBitmap7.Size))
e.Graphics.DrawImage(TabBitmap7, 50, 400, 1000, 500)
If Me.TextBox9.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 8
If Me.TextBox9.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage9
Dim TabBitmap8 As New Bitmap(TabControl1.TabPages(8).Width, TabControl1.TabPages(8).Height)
TabControl1.TabPages(8).DrawToBitmap(TabBitmap8, New Rectangle(Point.Empty, TabBitmap8.Size))
e.Graphics.DrawImage(TabBitmap8, 50, 400, 1000, 500)
If Me.TextBox10.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 9
If Me.TextBox10.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage10
Dim TabBitmap9 As New Bitmap(TabControl1.TabPages(9).Width, TabControl1.TabPages(9).Height)
TabControl1.TabPages(9).DrawToBitmap(TabBitmap9, New Rectangle(Point.Empty, TabBitmap9.Size))
e.Graphics.DrawImage(TabBitmap9, 50, 400, 1000, 500)
If Me.TextBox11.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 10
If Me.TextBox11.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage11
Dim TabBitmap10 As New Bitmap(TabControl1.TabPages(10).Width, TabControl1.TabPages(10).Height)
TabControl1.TabPages(10).DrawToBitmap(TabBitmap10, New Rectangle(Point.Empty, TabBitmap10.Size))
e.Graphics.DrawImage(TabBitmap10, 50, 400, 1000, 500)
If Me.TextBox12.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 11
If Me.TextBox12.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage12
Dim TabBitmap11 As New Bitmap(TabControl1.TabPages(11).Width, TabControl1.TabPages(11).Height)
TabControl1.TabPages(11).DrawToBitmap(TabBitmap11, New Rectangle(Point.Empty, TabBitmap11.Size))
e.Graphics.DrawImage(TabBitmap11, 50, 400, 1000, 500)
If Me.TextBox13.Text = "1" Then
e.HasMorePages = True
End If
End If
Case 12
If Me.TextBox13.Text = "1" Then
Me.TabControl1.SelectedTab = TabPage13
Dim TabBitmap12 As New Bitmap(TabControl1.TabPages(12).Width, TabControl1.TabPages(12).Height)
TabControl1.TabPages(12).DrawToBitmap(TabBitmap12, New Rectangle(Point.Empty, TabBitmap12.Size))
e.Graphics.DrawImage(TabBitmap12, 50, 400, 1000, 500)
e.HasMorePages = False
End If
End Select
PageNumber += 1