blob: bc1942a9f9759ec941357e0c59ac2baeaa56d8fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//
// 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();
}
}
|