468,241 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

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
Tr
PrnDoc = New PrintDocument(
PrnDialog.Document = PrnDo
If PrnDialog.ShowDialog() = DialogResult.OK The
DoPrint(
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

Tr
PrnDoc = New PrintDocument(

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

Private Sub DoPrint(
Tr
AddHandler PrnDoc.PrintPage, AddressOf Me.PrnDoc_PrintPag
PrnDoc.Print(
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 822

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Umesh | last post: by
2 posts views Thread by qumpus | last post: by
reply views Thread by KohlerTommy | last post: by
1 post views Thread by Karthic | last post: by
1 post views Thread by Anthony Nystrom | last post: by
1 post views Thread by Paolo matador | last post: by
reply views Thread by Mark | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.