从C#/。NET打印的最好方法? [英] Best way to print from c# / .net?

查看:257
本文介绍了从C#/。NET打印的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是打印从C#的东西的最佳方式/。NET?

What is the best way to print stuff from c#/.net?

的问题是关于单页以及含有大量的页的报告。

The question is in regard to single pages as well as to reports containing lots of pages.

这将是巨大的,获得包含每个人的主要特征和陷阱最常见的打印库列表。

It would be great to get a list of the most common printing libs containing the main features and gotchas of each of them.

[更新]标准Windows客户端(或服务器),而不是Web应用程序,请。

[Update] for standard windows clients (or servers), not for web apps, please.

推荐答案

有关报道,我用的是RDLC控制。

For reports, I use the RDLC control.

对于一切,我用在.NET中固有的打印对象。

For everything else, I use the inherent printing objects within .NET.

修改 固有的打印对象在System.Drawing.Printing命名空间中找到的所有。当您使用PrintDialog类或打印previewDialog在一个WinForms(或WPF)应用程序,这是给你翻身的控制这些对象。

Edit The inherent printing objects are all found in the System.Drawing.Printing namespace. When you use the PrintDialog or the PrintPreviewDialog in a WinForms (or WPF) application, it is to these objects that you're turning over control.

的基本概念是,你正在绘制到打印机。这种最简单的形式是:

The fundamental concept is that you're drawing to the printer. The simplest form of this is:

Sub MyMethod()
     Dim x as New PrintDocument
     AddHandler x.PrintPage, AddressOf printDoc_PrintPage
     x.Print
End Sub
Sub printDoc_PrintPage( sender as Object,  e as PrintPageEventArgs)
      Dim textToPrint as String= ".NET Printing is easy"
      dim printFont as new Font("Courier New", 12)
      dim leftMargin as int= e.MarginBounds.Left
      dim topMargin as int = e.MarginBounds.Top
      e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin)
End Sub

这里发生的是,当我的对象(X)发送打印命令,它提出了打印页面事件(其目的是在同一时间打印1页)。此事件然后使用PrintPageEventArgs的图形属性直接绘制相关的字符串,打印后台处理程序。

What's happening here is that when my object (x) is sent the print command, it raises the "PRINT PAGE" event (which is designed to print 1 page at a time). This event then uses the Graphics attribute of the PrintPageEventArgs to draw the relevant string directly to the print spooler.

这里有一个教程和一快速谷歌搜索.NET打印教程返回有点超过200K的结果。

Here's one tutorial, and a quick Google search for ".NET printing tutorial" returns a bit over 200K results.

这篇关于从C#/。NET打印的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆