Wpf how to print ListBox

╄→尐↘猪︶ㄣ 提交于 2019-12-08 02:04:01

问题


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.


回答1:


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)

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();

or

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


来源:https://stackoverflow.com/questions/4522038/wpf-how-to-print-listbox

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