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... -
Private Sub PrintPageHandler(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
-
Try
-
-
Dim psz As New Printing.PaperSize
-
-
-
psz.PaperName = Printing.PaperKind.A4
-
e.PageSettings.PaperSize = psz
-
e.PageSettings.Landscape = True
-
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
Anyone able to point me in the right direction?
Regards,
Scott
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.
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
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?
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
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: -
Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
-
Dim prn As New Printing.PrintDocument
-
Dim pageSettings As System.Drawing.Printing.PageSettings = New System.Drawing.Printing.PageSettings
-
-
pageSettings.Landscape = True
-
pageSettings.PaperSize = New System.Drawing.Printing.PaperSize("A4", 210, 297)
-
pageSettings.Margins.Top = 0
-
pageSettings.Margins.Bottom = 0
-
pageSettings.Margins.Left = 0
-
pageSettings.Margins.Right = 0
-
-
prn.DefaultPageSettings = pageSettings
-
prn.PrinterSettings.PrinterName.ToString()
-
-
AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
-
prn.Print()
-
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
-
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
Get codeforms, it will do all the printing coding for you. its free:
http://www.neuronlabs.com/sendfile.php?file=nlsw0001.html
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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;...
|
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...
|
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.)...
|
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...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |