Printing causes page feed at each DrawString()
Posted on 2004-09-14
Leave it to Microsoft to take a nice simple concept like the Printer object and turn it into something so convuluted it's a pain to use or even figure out how to use.
Now that rant is over, on to my problem/question.
I've been working on a class to emulate the old VB6 Printer object. It's working well so far except every time I print a line, I get a page feed.
The trimmed sections of my class are as follows:
Public Class TextPrint
' Inherits all the functionality of a PrintDocument
' Private variables to hold default font and text
Private m_fntPrintFont As Font
Private m_sText As String
Private m_nCurrentX As Integer
Private m_nCurrentY As Integer
Public Sub New()
Public Shadows Sub [Print](ByVal sText As String)
m_sText = sText
Protected Overrides Sub OnBeginPrint(ByVal ev As Printing.PrintEventArgs)
' Run base code
' Sets the default font
If m_fntPrintFont Is Nothing Then
m_fntPrintFont = New Font("Times New Roman", 12)
Protected Overrides Sub OnPrintPage(ByVal ev As Printing.PrintPageEventArgs)
' Provides the print logic for our document
' Run base code
ev.Graphics.DrawString(m_sText, m_fntPrintFont, Brushes.Black, m_nCurrentX, m_nCurrentY)
ev.HasMorePages = False
The code that calls the class is as follows:
Dim Printer As New TextPrint
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Printer.Print("This is line 1")
Printer.Print("This is line 2")
Two questions in one...
1. How do I stop the printer from page feeding between "This is line 1" and "This is line 2"?
2. Once I stop if from page feeding when I don't want it, how to I force a page feed (ala EndDoc)?