Calling PageSetupDialog from a PrintPreviewDialog

P

ppeterkin

I customized a PrintPreviewDialog by adding a button to it's toolstrip
that opens up a PageSetupDialog. The problem is changes made to the
page setup are not passed to the PrintPreviewDialog until I close and
reload it.
How do I enable these changes to immediately show up in the print
preview. See Code Below.

Paul

Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
Dim dlgPrintPreview As New PrintPreviewDialog
Dim PageSetButton As New ToolStripButton

PageSetButton.ToolTipText = "Page Setup"
PageSetButton.Text = "Setup"
tb = DirectCast(dlgPrintPreview.Controls(1), ToolStrip)
For i As Integer = 4 To 7
' tbt = tb.Items(i)
' tbt.Visible = False
tb.Items.RemoveAt(i)
Next
AddHandler PageSetButton.Click, AddressOf PageSetup
tb.Items.Add(PageSetButton)
dlgPrintPreview.Document = PrintDoc
dlgPrintPreview.ShowDialog()
End Sub

Private Sub PageSetup(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripMenuItem1.Click
Try
' show page setup dialog
Dim pageSetupDialog As PageSetupDialog = New
PageSetupDialog()

pageSetupDialog.PrinterSettings = PrintDoc.PrinterSettings
pageSetupDialog.PageSettings =
PrintDoc.DefaultPageSettings

If pageSetupDialog.ShowDialog() =
Windows.Forms.DialogResult.Cancel Then
Return
End If

' save changes
PrintDoc.PrinterSettings = pageSetupDialog.PrinterSettings
PrintDoc.DefaultPageSettings =
pageSetupDialog.PageSettings
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top