簡體   English   中英

從 WPF 無聲打印

[英]Silent printing from WPF

我想禁用此打印對話框:對話

我應該怎么做才能刪除這個對話框?

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

您可以使用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);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM