mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 17:10:20 -10:00
* EnumPrinters.cs: Printer enumerator * PrintingTextFile.cs: Prints a text file svn path=/trunk/mcs/; revision=54738
55 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|
|
|
|
|