Really cant get your Idea behind this.. As Dave Kreskowiak says about the possible errors of your case. But I am working on a project where I need PrintPreviewDialog and I need to select a printer instead of direct print of document when Print option of PrintPreviewDialog is clicked. So I managed to do
1. manipulate Print Toolstrip of the PrintPreviewDialog
2. Add a Handler to PrintDocument.PrintPage event and PrintPreview.PrintClick event
Private Sub Print_btn_Click(sender As Object, e As EventArgs) Handles Print_btn.Click
Dim b As New ToolStripButton
b.Image = CType(PrintPreviewDialog1.Controls(1), ToolStrip).ImageList.Images(0)
b.ToolTipText = "Print"
b.DisplayStyle = ToolStripItemDisplayStyle.Image
AddHandler b.Click, AddressOf PrintPreview_PrintClick
CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.RemoveAt(0)
CType(PrintPreviewDialog1.Controls(1), ToolStrip).Items.Insert(0, b)
AddHandler PrintDocument1.PrintPage, AddressOf PrintDocument1_PrintPage
PrintPreviewDialog1.Document = PrintDocument1
PrintDocument1.OriginAtMargins = False
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintPreview_PrintClick(sender As Object, e As EventArgs)
Try
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
End Try
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Me.BackgroundImage = WindowsApp1.My.Resources.Resources.WhiteBackground
Dim print_bmp As Bitmap = GetClientareaImage(Me)
e.Graphics.DrawImage(print_bmp, 0, 0)
End Sub
I need to print the image of form's client area. So I write the function "GetClientareaImage()" which has no Relation to this solution. Thats why I am not posting it.