问题
I have some text displayed in a TextView which I want to print. I've been googling for 2 whole hours now. If anyone could help me out with this, you'd really make my day. Thanks!
回答1:
Here's a very simple example (tested on a Windows machine):
PrintDocument doc = new PrintDocument();
var printFont = new Font("Arial", 10);
doc.PrintPage += (s, ev) => {
ev.Graphics.DrawString("Your text goes here",
printFont,
Brushes.Black,
ev.MarginBounds.Left,
ev.MarginBounds.Top);
HasMorePages = false;
};
doc.Print();
You'll have to add a reference to System.Drawing
and these two using
statements :
using System.Drawing;
using System.Drawing.Printing;
回答2:
The code on this page excellently explains how this can be done: http://www.mail-archive.com/gtk-sharp-list@lists.ximian.com/msg03762.html
来源:https://stackoverflow.com/questions/12873640/how-to-print-plain-text-using-monodevelop-and-c