R
RG
Hi. I’m enhancing a VB.NET 2003 application that prints a document, to
include showing the standard Print Dialog so the user can choose which
printer to use (it currently just uses the default printer).
I’m currently successfully showing & using the standard Print Dialog using
this code:
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
Printer_selectd = PrintDocument1.PrinterSettings.PrinterName
End If
Here’s my problem/question:
How can I create a new PrintDialog object and PrintDocument object IN MY CODE?
The reason that’s necessary is that this application (that I’ve inherited)
uses NO FORMs: it just starts at Sub Main, and goes to the end. Therefore I
can’t just drag a new PrintDialog object and PrintDocument object from the
toolbox onto a Form (there isn’t one).
Just to get something to work, I created a small form that I call in the
code with ShowDialog, and I dragged a new PrintDialog object and
PrintDocument object from the toolbox onto it. I put a button on the form,
and upon clicking the button, it runs the code above which shows the Print
Dialog. This works, but the added Form-clicking is unacceptable to the user.
I imagine the answer to my question is something like this, but I just can’t
get it to work:
Dim Printdocument1 As New System.Drawing.printing.Printdocument
Dim PrintDialog1 As New System.Windows.Forms.PrintDialog
Thanks for any advice.
include showing the standard Print Dialog so the user can choose which
printer to use (it currently just uses the default printer).
I’m currently successfully showing & using the standard Print Dialog using
this code:
PrintDialog1.Document = PrintDocument1
PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages = True
If PrintDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
Printer_selectd = PrintDocument1.PrinterSettings.PrinterName
End If
Here’s my problem/question:
How can I create a new PrintDialog object and PrintDocument object IN MY CODE?
The reason that’s necessary is that this application (that I’ve inherited)
uses NO FORMs: it just starts at Sub Main, and goes to the end. Therefore I
can’t just drag a new PrintDialog object and PrintDocument object from the
toolbox onto a Form (there isn’t one).
Just to get something to work, I created a small form that I call in the
code with ShowDialog, and I dragged a new PrintDialog object and
PrintDocument object from the toolbox onto it. I put a button on the form,
and upon clicking the button, it runs the code above which shows the Print
Dialog. This works, but the added Form-clicking is unacceptable to the user.
I imagine the answer to my question is something like this, but I just can’t
get it to work:
Dim Printdocument1 As New System.Drawing.printing.Printdocument
Dim PrintDialog1 As New System.Windows.Forms.PrintDialog
Thanks for any advice.