Files
Jordi Mas i Hernandez be3852e52b 2005-12-22 Jordi Mas i Hernandez <[email protected]>
* EnumPrinters.cs: Printer enumerator
	* PrintingTextFile.cs: Prints a text file


svn path=/trunk/mcs/; revision=54738
2005-12-22 17:26:18 +00:00

55 lines
1.1 KiB
C#

//
// Simple text file printing sample
//
using System;
using System.Drawing;
using System.IO;
using System.Drawing.Printing;
public class PrintingTextFile
{
private static StreamReader stream;
static private void PrintPageEvent (object sender, PrintPageEventArgs e)
{
float lines_page, y;
int count = 0;
float left = e.MarginBounds.Left;
float top = e.MarginBounds.Top;
String line = null;
Font font = new Font ("Arial", 10);
float font_height = font.GetHeight (e.Graphics);
lines_page = e.MarginBounds.Height / font_height;
while (count < lines_page) {
line = stream.ReadLine ();
if (line == null)
break;
y = top + (count * font_height);
e.Graphics.DrawString (line, font, Brushes.Black, left, y, new StringFormat());
count++;
}
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
public static void Main (string[] args)
{
stream = new StreamReader ("PrintMe.txt");
PrintDocument p = new PrintDocument ();
p.PrintPage += new PrintPageEventHandler (PrintPageEvent);
p.Print ();
stream.Close();
}
}