Wpf how to print ListBox

2019-05-22 22:19发布

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.

标签: wpf listbox
1条回答
地球回转人心会变
2楼-- · 2019-05-22 22:55

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);
查看更多
登录 后发表回答