I have a graphic file demo program that almost works. My form has a
PageSetupDialog, PrintPreview, PrintDialog, and a PrintDocument control.
Sample code follows.
Now here is the quesion. When I open the PrintDialog control, there is a
dropdown to select a printer from the list of available printers. However,
the PageSetupDialog sets the properties of the "selected" printer. How do I
find and select one of the available printers so I can , for example, select
the paper size and set up the page margins using the PageSetupDialog before I
select the printer using the PrintDialog?
More specifically, My default printer, a laserjet 4P only prints on 8 1/2 X
11 paper. I also have a HP5500C that can also print on 11 X 17 paper. Before
printing, I need to be able to select the HP500C so I then have the option to
select a 11X17 size and then set the print margins.
I hope this makes sense.
Hamil.
'************************************************* *******
Private PrintPageSettings As New PageSettings()
Private Sub btnPageSetup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSetup.Click
Try
'Load page settings and display page setup dialog box
PageSetupDialog1.PageSettings = PrintPageSettings
PageSetupDialog1.ShowDialog()
Catch ex As Exception
'Display error message
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPreview.Click
Try
'Specify current page settings
PrintDocument1.DefaultPageSettings = PrintPageSettings
'Specify document for print preview dialog box and show
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
'Display error message
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage
Dim numChars As Integer
Dim numLines As Integer
Dim stringForPage As String
Dim strFormat As New StringFormat
'Based on page setup, define drawable rectangle on page
Dim rectDraw As New RectangleF( _
e.MarginBounds.Left, e.MarginBounds.Top, _
e.MarginBounds.Width, e.MarginBounds.Height)
e.Graphics.DrawImage(Image.FromFile("E:\MuView\Alt o1-1.tif"),
rectDraw)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrint.Click
Try
'Specify current page settings
PrintDocument1.DefaultPageSettings = PrintPageSettings
'Specify document for print dialog box and show
PrintDialog1.Document = PrintDocument1
Dim result As DialogResult = PrintDialog1.ShowDialog()
'If click OK, print document to printer
If result = DialogResult.OK Then
PrintDocument1.Print()
End If
Catch ex As Exception
'Display error message
MessageBox.Show(ex.Message)
End Try
End Sub