PDA

Click to See Complete Forum and Search --> : stop printer feeding


basti42
Aug 13th, 2007, 01:53 AM
namespace PrintTextFile
{
public partial class Form1 : Form
{
StreamReader fileToPrint = new System.IO.StreamReader( @"C:\sample.txt");
Font printFont = new System.Drawing.Font("Consolas", 10);

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
printDocument1.Print();
fileToPrint.Close();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float yPos = 0f;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
string line = null;
float linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
while (count < linesPerPage)
{
line = fileToPrint.ReadLine();
if (line == null)
{
break;
}
yPos = topMargin + count * printFont.GetHeight(e.Graphics);
e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
count++;
}
if (line != null)
{
e.HasMorePages = true;
}
}
}
}


above code will print the contents of c:\sample.txt
but how could stop the printer in feeding?
for example if there are 3 or 4 lines in a text file. after 3rd lines printed it will stop from feeding...
any suggestions?