472,802 Members | 1,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 software developers and data experts.

Printer settings problem

Print Problem

Hey all,
I’m new to Visual Basic dot net. I’m trying to understand printing a little better. Here’s the problem. If I create a PrintDocument and use a PrintDialog, then My Print out is to the page size specified in the PrintDialog settings. But if I try to manually set a page size and print without using the PrintDialog then my page settings are not used
The following is some code that I am using to try to understand this.

Private PrnFont As New Font("Arial", 10
Private PrnDoc As PrintDocumen

Private Sub butPrintDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butPrintDialog.Clic
PrnDoc = New PrintDocument(
PrnDialog.Document = PrnDo
If PrnDialog.ShowDialog() = DialogResult.OK The
End I
Catch Excep As Exceptio
MessageBox.Show(Excep.Message, "Printing Error", MessageBoxButtons.OK, MessageBoxIcon.Error
End Tr
End Su

Private Sub butPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butPrint.Clic

PrnDoc = New PrintDocument(

Dim PgSize As New PaperSize("Custom", 450, 350
PrnDoc.PrinterSettings.DefaultPageSettings.PaperSi ze = PgSiz
Catch Excep As Exceptio
MessageBox.Show(Excep.Message, "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error
End Tr
End Su

Private Sub DoPrint(
AddHandler PrnDoc.PrintPage, AddressOf Me.PrnDoc_PrintPag
Catch Excep As Exceptio
MessageBox.Show(Excep.Message, "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error
End Tr

End Su

Private Sub PrnDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs
Dim nLinesPerPage As Single =
Dim YPos As Single =
Dim Count As Integer =
Dim LeftMargin As Single = e.MarginBounds.Lef
Dim TopMargin As Single = e.MarginBounds.To
Dim szLine As String = Nothin

' Calculate the number of lines per page
nLinesPerPage = e.MarginBounds.Height / PrnFont.GetHeight(e.Graphics

'Print each line
While nLinesPerPage >
szLine = "This is line No: " & (Count + 1
YPos = TopMargin + Count * PrnFont.GetHeight(e.Graphics
e.Graphics.DrawString(szLine, PrnFont, Brushes.Black, LeftMargin, YPos, New StringFormat()
Count +=
nLinesPerPage -=
End Whil

e.HasMorePages = Fals

End Su

Nov 20 '05 #1
0 971

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter ,...
by: qumpus | last post by:
My program right now generates USPS style shipping label using System.Drawing.Graphics. It works fine except that the printer prints really slowly. I want to make my program take advantage of true...
by: KohlerTommy | last post by:
In my application I need to give the user the ability to print duplex if the selected printer supports duplex printing. Many of the printer options do not make much sense in my application, and...
by: Karthic | last post by:
When i right click on the .rpt file in the VS 2003, i see a property printer setting. It says "No printer" on the top and there is option to select printer and paper settings etc.. I want to...
by: Anthony Nystrom | last post by:
I need to within code control some printer settings before raising the print dialog... I need to set some properties for the printer such as "The Printer to Print too", Page settings such as paper...
by: Paolo matador | last post by:
Hi All, i have a little problem with my web application. I need to print a web page, shrinked on a thermal printer that not supporting A4 format. The printer is this:...
by: sathyp | last post by:
Public Function SetPrinterDefaultsW(ByVal sPrinterName As String, _ ByVal nPaperSize As Long, ByVal nOrientation As Long) As Boolean Dim Prn As Printer Dim hPrinter As Long Dim pd As...
by: Mark | last post by:
Hello, I have a VB6 Project that uses an ini file to save selected printer settings for several forms. The program allows users to select the printer on their work station for printing forms. If...
by: Giovanni Benedetti | last post by:
Hi everybody, sorry for my English first of all. I've an ASP page (ASP 3.0) used on an intranet which fill up some particular Mail sheets getting data from a database. Those pre-compiled sheets...
by: brianflannery | last post by:
Greetings all! My problem is this. I've installed a new printer on my computer. This is the "default printer" for access. Now, some of my reports, which were working fine with the old printer,...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.