gpt4 book ai didi

c# - 为 Windows 客户端(而非 Web 应用程序)打印的最佳方式?

转载 作者:可可西里 更新时间:2023-11-01 08:22:20 25 4
gpt4 key购买 nike

从 c#/.net 打印内容的最佳方式是什么?

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

如果能得到一份最常见的打印库列表,其中包含每个库的主要功能和陷阱,那就太好了。

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

最佳答案

对于报告,我使用 RDLC 控件。

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

编辑固有的打印对象都可以在 System.Drawing.Printing 命名空间中找到。当您在 WinForms(或 WPF)应用程序中使用 PrintDialog 或 PrintPreviewDialog 时,您正在将控制权交给这些对象。

基本概念是您正在向打印机绘图。最简单的形式是:

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) 收到打印命令时,它会引发“PRINT PAGE”事件(旨在一次打印 1 页)。然后,此事件使用 PrintPageEventArgs 的图形属性将相关字符串直接绘制到后台打印程序。

Here's one tutorial ,然后在 Google 上快速搜索“.NET 打印教程”会返回超过 20 万个结果。

关于c# - 为 Windows 客户端(而非 Web 应用程序)打印的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/371384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com