473,474 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PrinterSettings in VB.NET

Scott Price
1,384 Recognized Expert Top Contributor
Hello kind folks over here!

I'm taking a hiatus from developing a couple of databases to work a little with VB.Net. My problem is understanding how to send page settings to the printer bypassing the Page Settings dialog box. For my application there will be no need for anyone to change paper sizes, margins, etc etc etc... so why give them too many options, eh?

This code section is what I've been trying to use to send the paper size and layout, i.e. landscape to the printer, however it doesn't seem to do much towards making the printer listen when it talks...

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
  2.         Try
  3.  
  4.             Dim psz As New Printing.PaperSize
  5.  
  6.  
  7.             psz.PaperName = Printing.PaperKind.A4
  8.             e.PageSettings.PaperSize = psz
  9.             e.PageSettings.Landscape = True
  10.  
  11.         Catch ex As Exception
  12.             MessageBox.Show(ex.Message)
Anyone able to point me in the right direction?

Regards,
Scott
Feb 18 '08 #1
6 12967
Plater
7,872 Recognized Expert Expert
Have you taken a look at:
System.Drawing.Printing.PrintDocument
yet? I think you need to use one of those for such things.
Feb 18 '08 #2
Scott Price
1,384 Recognized Expert Top Contributor
Well, that was fast!

Thanks for the suggestion, but unless I'm not understanding exactly how to implement it, that doesn't work either.

I've tried initializing a new Printing.PrintDocument object, then setting the DefaultPageSettings to the paper size and landscape orientation that I want, however it does the same as the first code: compiles fine, executes fine but doesn't make the printer listen when it talks :-)

Thanks again,
Regards,
Scott
Feb 18 '08 #3
Plater
7,872 Recognized Expert Expert
Hehe, I believe THAT was the PrintDocument I ment to link.
There used to be an article on Printing in the how-to's, but it appears to not be there anymore. Only thing that might help would be to search this forum for other's on Printing and see what they came up with?
Feb 18 '08 #4
Scott Price
1,384 Recognized Expert Top Contributor
First thing I done was search the posts here :-) No joy.

I'll keep researching... It seems an awfully complicated way to do things, so far I've found at least three different objects that have PageSettings properties, none of which seem to be working for me. I'll post back if I ever do get it to work.

Thanks again, and kind regards,
Scott
Feb 18 '08 #5
Scott Price
1,384 Recognized Expert Top Contributor
Well, this is what I've found out so far: vb.net isn't exactly as easy to understand as vba :-)

This is the sub I've gotten to work setting the landscape, margins and papersize:
Expand|Select|Wrap|Line Numbers
  1. Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
  2.         Dim prn As New Printing.PrintDocument
  3.         Dim pageSettings As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings
  4.  
  5.         pageSettings.Landscape = True
  6.         pageSettings.PaperSize = New System.Drawing.Printing.PaperSize("A4", 210, 297)
  7.         pageSettings.Margins.Top = 0
  8.         pageSettings.Margins.Bottom = 0
  9.         pageSettings.Margins.Left = 0
  10.         pageSettings.Margins.Right = 0
  11.  
  12.         prn.DefaultPageSettings = pageSettings
  13.         prn.PrinterSettings.PrinterName.ToString()
  14.  
  15.         AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
  16.         prn.Print()
  17.         RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
  18.     End Sub
Someone else might run into this problem sometime too :-) This includes a call to the PrintPageHandler routine, which is a custom routine that builds the rectangles, strings, etc that I'm putting onto the page.

Thanks Plater!

Regards,
Scott
Feb 18 '08 #6
lorenzana
3 New Member
Get codeforms, it will do all the printing coding for you. its free:

http://www.neuronlabs.com/sendfile.php?file=nlsw0001.html
Feb 27 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: RBisch | last post by:
I am finding that some of the properties off of the PrinterSettings object are misleading For example, When I test the CanDuplex on a printer I know duplexes, the property is false. Another one...
3
by: Steve Hanna | last post by:
I am having problems using the Printer Dialog to set PrinterSettings, specifically the landscape property of the DefaultPageSettings. Here's the code: <code> Private Sub GetPrinter(ByRef...
1
by: Richard Golebiowski | last post by:
I have been trying to figure this out for quite some time and cannot find any examples in VB.Net or in VB that work correctly. I am working on an application where I want the user to be able to...
3
by: Jochen Kalmbach | last post by:
Hello, if an PrinterSettings-Instance is not set-up correctly (for example just by using the default-constructor), then the "ToString()"_method will throw an exception! Unhandled...
2
by: Robert Hooker | last post by:
Hi, I'm curious to know if I'm doing something wrong here, or if this is just mind-numbingly slow for a reason. In a simple WindowsFormsApplication: public Form1() { // Required for...
1
by: Sachin | last post by:
I have multiple printer drivers installed (e.g. EPSON, RICOH, CANNON) on my computer. Is there any way to check/get the PrinterSettings of any of them using Printer Name? i.e. if I want to check...
0
by: trint | last post by:
try { // Wait for the report to completely render. if(m_numberOfPages < 1) return false; PrinterSettings printerSettings = new PrinterSettings(); printerSettings.MaximumPage = m_numberOfPages;...
3
by: trint | last post by:
Can someone help me to get this code to work...I'm unsure what the 'printDoc' variable is supposed to be? // Add list of paper sources found on the printer to the combo box. // The DisplayMember...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
2
by: =?Utf-8?B?RGF2aWQ=?= | last post by:
I’m not sure how to feed PCL commands (i.e. “Ec&l1S”) thru the PrinterSettings() function, but we have been successfully using the PrinterSetting() properties and methods to successfully call...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.