How to print plain text using Monodevelop and C#?

前提是你 提交于 2019-12-12 19:14:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!