Problem using standard Print Dialog in VB.NET 2003

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.
 
A

Armin Zingler

RG said:
[...]
How can I create a new PrintDialog object and PrintDocument object
IN MY CODE?

Aren't the lines below the answer?
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

This should work. What problem do you encounter?


Armin
 
F

Family Tree Mike

I believe RG is saying it is a console app, so it is likely missing a
reference or two to System.Windows.Forms.dll and System.Drawing.dll.


Armin Zingler said:
RG said:
[...]
How can I create a new PrintDialog object and PrintDocument object
IN MY CODE?

Aren't the lines below the answer?
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

This should work. What problem do you encounter?


Armin
 
A

Armin Zingler

Family Tree Mike said:
I believe RG is saying it is a console app, so it is likely missing
a reference or two to System.Windows.Forms.dll and
System.Drawing.dll.

Yes, possible. I thought he has set it because he wrote "Just to get
something to work, I created a small form...", but maybe not in the
same project.


Armin
 

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