用 C# 打印 (wpf) [英] Printing in C# (wpf)

查看:32
本文介绍了用 C# 打印 (wpf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 C# WPF 程序,我的程序必须能够打印发票,但我有点努力想知道在 WPF 中打印是如何工作的......如果我记得在 winforms 中编程,有你会使用 GDI+ 打印.但是,我认为 WPF 并非如此.

I'm making a C# WPF program, and my program has to be able to print invoices, but I'm kinda struggling to find out how printing works in WPF... If I remember well from programming in winforms, there you'd use GDI+ to print. However, I assume that's not the case with WPF.

如果有人能通过一些指向有用文档或示例的链接为我指明正确的方向,我会非常高兴...

I would be very happy if someone could point me in the right direction with some links to helpful documents or examples...

推荐答案

在 WPF 中打印既简单又不那么简单.

Printing in WPF is both simple and not so simple.

它基本上从您已经打印的一两行代码开始.

It starts with basically with one or two lines of code you are printing already.

private void PrintBtn_Click(object sender, RoutedEventArgs e)
{
    PrintDialog printDialog = new PrintDialog();
    if (printDialog.ShowDialog() == true)
    {
    printDialog.PrintVisual(grid, "My First Print Job");
    }
}

但是,WPF 中的分页不是通过一行代码完成的.然后你会进入 FlowDocuments 和类似的更高级的主题.

However, pagination in WPF is not done with a single line of code. Then you get into FlowDocuments and similar more advanced topics.

如果你是为自己制作非商业工具,可以考虑iTextSharp,非常好

If you are making a non-commercial tool for yourself, consider iTextSharp which is very good too.

这篇关于用 C# 打印 (wpf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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