I am not sure if this fits in some other forum thread but here goes...
I have an application in which I open larger number of files create a specific report (I fill in values in a usercontrol with 3 tabpages and some textboxes labels and graph on each of them) for each and would like to print this control silently (meaning never to open it for user to view)...
it works great if I open it and print then, but if I only fill the report and try to print this I just get a blank page. (I am printing in a pdf printer to save paper
- for now), although here also if I only look at first tabpage and print all 3 of them (but never actually clicking on the rest) I only get a print of first tabpage and the second two pages are again blank.
The code I use to print:
Any help is greatly appreciated.
Regards,
Greg
I have an application in which I open larger number of files create a specific report (I fill in values in a usercontrol with 3 tabpages and some textboxes labels and graph on each of them) for each and would like to print this control silently (meaning never to open it for user to view)...
it works great if I open it and print then, but if I only fill the report and try to print this I just get a blank page. (I am printing in a pdf printer to save paper
The code I use to print:
VB.NET:
Public Class PrintMe
Dim printdialog1 As New PrintDialog
Dim WithEvents PrintDocument1 As New Printing.PrintDocument
Private bmp As Bitmap
Public tp() As TabPage
'Public tc As TabControl
Private tabpagecount As Integer = 0
Public Sub Print() 'ByVal _ucreportpreview As ucReportPreview
'_ucreportpreview.TpPS.DrawToBitmap(bmp, _ucreportpreview.TpPS.DisplayRectangle)
With printdialog1
'If PrintDocument1.DefaultPageSettings.PaperSize.Width - bmp.Width < 12 Then
If PrintDocument1.DefaultPageSettings.PaperSize.Width - tp(tabpagecount).Width < 12 Then
PrintDocument1.DefaultPageSettings.Margins.Left = Convert.ToInt32((3.0 / 25.4) * 100)
PrintDocument1.DefaultPageSettings.Margins.Right = Convert.ToInt32((3.0 / 25.4) * 100)
Else
'PrintDocument1.DefaultPageSettings.Margins.Left = (PrintDocument1.DefaultPageSettings.PaperSize.Width - bmp.Width) / 2
PrintDocument1.DefaultPageSettings.Margins.Left = (PrintDocument1.DefaultPageSettings.PaperSize.Width - tp(tabpagecount).Width) / 2
PrintDocument1.DefaultPageSettings.Margins.Right = PrintDocument1.DefaultPageSettings.Margins.Left
End If
PrintDocument1.DefaultPageSettings.Margins.Top = Convert.ToInt32((3.0 / 25.4) * 100)
'If PrintDocument1.DefaultPageSettings.PaperSize.Height - bmp.Height < 12 Then
If PrintDocument1.DefaultPageSettings.PaperSize.Height - tp(tabpagecount).Height < 12 Then
PrintDocument1.DefaultPageSettings.Margins.Bottom = Convert.ToInt32((3.0 / 25.4) * 100)
Else
'PrintDocument1.DefaultPageSettings.Margins.Bottom = PrintDocument1.DefaultPageSettings.PaperSize.Height - bmp.Height
PrintDocument1.DefaultPageSettings.Margins.Bottom = PrintDocument1.DefaultPageSettings.PaperSize.Height - tp(tabpagecount).Height
End If
.Document = PrintDocument1
If printdialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
End With
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
bmp = New Bitmap(tp(tabpagecount).Width, tp(tabpagecount).Height)
tp(tabpagecount).DrawToBitmap(bmp, tp(tabpagecount).DisplayRectangle)
tabpagecount += 1
e.Graphics.DrawImage(bmp, e.MarginBounds)
If tabpagecount < tp.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
bmp = Nothing
End If
End Sub
End Class
Any help is greatly appreciated.
Regards,
Greg