using System;
using System.Drawing;
using System.IO;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace PrintApp
{
public class Form1 : Form
{
private PrintDocument printDocument1
= new PrintDocument
(); private string stringToPrint;
private void LeerArchivo()
{
string docName = "archivo.txt";
string docPath = @"c:";
printDocument1.DocumentName = docName;
using (FileStream stream
= new FileStream
(docPath
+ docName, FileMode
.Open)) using (StreamReader reader
= new StreamReader
(stream
)) {
stringToPrint = reader.ReadToEnd();
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
stringToPrint = stringToPrint.Substring(charactersOnPage);
e.HasMorePages = (stringToPrint.Length > 0);
}
private void printButton_Click(object sender, EventArgs e)
{
LeerArchivo();
printDocument1.Print();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application
.Run(new Form1
()); }
}
}