WPF如何打印ListBox [英] Wpf how to print ListBox

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

问题描述

我想知道打印ListBox值的最简单方法是什么.我尝试使用FlowDocumentReader,但没有成功.

I would like to know what is the easiest way to print ListBox's values. I have tried to use FlowDocumentReader but with no success.

推荐答案

如果您尝试打印视觉元素,则可以使用

If you are trying to print a visual element,you can use

             PrintDialog printDlg = new PrintDialog();
             printDlg.PrintVisual(ListBox1, "Listbox Printing.");

它可用于打印任何视觉对象(任何控件,容器,窗口或用户控件)

It can be used to print any visual object(any control, container, Window or user control)

如果您只想打印项目,则可以使用FlowDocument

If you are looking to print the items only then you can use the FlowDocument

             FlowDocument fd = new FlowDocument();
             foreach (object item in items)
             {
                 fd.Blocks.Add(new Paragraph(new Run(item.ToString())));
             }
             fd.Print();

             PrintDialog pd = new PrintDialog();
             pd.PrintDocument(fd);

这篇关于WPF如何打印ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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