Wpf how to print ListBox

倾然丶 夕夏残阳落幕 提交于 2019-12-06 10:32:27

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