简体   繁体   中英

How to print plain text using Monodevelop and C#?

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!

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;

此页面上的代码很好地解释了如何完成此操作: http : //www.mail-archive.com/gtk-sharp-list@lists.ximian.com/msg03762.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM