【问题标题】:Silent printing from WPF来自 WPF 的静默打印
【发布时间】:2021-02-19 11:42:59
【问题描述】:

我想禁用此打印对话框:

我应该怎么做才能删除这个对话框?

var dlg = new PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = false;
var doc = new FlowDocument();
    doc.PageWidth = 275;
    doc.FontSize = 18;
    doc.TextAlignment = TextAlignment.Center;
    doc.Blocks.Add(new Paragraph(new Run("nXXXXXXXXXXXX")));
dlg.PrintDocument(((IDocumentPaginatorSource)doc).DocumentPaginator, "Receipt");

【问题讨论】:

标签: c# wpf printing


【解决方案1】:

您可以使用PrintDocument class 代替PrintDialog。请参阅微软的实现

    try
    {
        streamToPrint = new StreamReader
           ("C:\\My Documents\\MyFile.txt");
        try
        {
            printFont = new Font("Arial", 10);
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler
               (this.pd_PrintPage);
            pd.Print();
        }
        finally
        {
            streamToPrint.Close();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 2015-05-07
    • 2020-07-05
    • 2013-11-08
    • 2017-05-24
    • 2010-11-01
    • 1970-01-01
    相关资源
    最近更新 更多