选择打印机名称而不显示PrintDialog

时间:2019-02-08 01:48:02

标签: c# printing report

我有这个代码。当我需要打印报告时,它会显示一个“打印对话框”。我想通过代码选择打印名称,并在不显示PrintDialog的情况下打印报告。

这是我的代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace POS.Reports
{
public partial class ProductsReceiptPreview : Form
{
    BindingSource _data;
    string _total, _cashr, _cashc;
    public ProductsReceiptPreview(BindingSource data, string total, 
string cashr, string cashc)
    {
        InitializeComponent();
        _total = total; _cashr = cashr; _cashc = cashc;
        _data = data;
    }

    private void ProductsReceipt_Load(object sender, EventArgs e)
    {
        DataReceiptBindingSource.DataSource = _data;
        Microsoft.Reporting.WinForms.ReportParameter[] param = new 
        Microsoft.Reporting.WinForms.ReportParameter[]
        {
           new Microsoft.Reporting.WinForms.ReportParameter("ptotal", 
    _total),
            new Microsoft.Reporting.WinForms.ReportParameter("pcashr", 
    _cashr),
             new Microsoft.Reporting.WinForms.ReportParameter("pcashc", 
    _cashc),
            new Microsoft.Reporting.WinForms.ReportParameter
    ("pdate",DateTime.Now.ToString())
        };
        this.rptProductsReceipt.LocalReport.SetParameters(param);
        this.rptProductsReceipt.RefreshReport();
        this.rptProductsReceipt.ZoomMode = 
    Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
    }


    private void btnReports_Click(object sender, EventArgs e)
    {
        rptProductsReceipt.PrintDialog();
    }

}
}

1 个答案:

答案 0 :(得分:0)

我从不使用您的方法,但是我使用了

rptProductsReceipt.PrintToPrinter(1, false, 0, 0);

使用适配器和数据表后