代碼始下:結果是預覽沒問題,但是打印機設定中不是我的自定義紙張大小PrinterSettings ps = new PrinterSettings(); PrintPreview pp = new PrintPreview(); Form w = new waiting(); try { w.Show(); DataSet DSXHDP = new DataSet(); byte[] b = POS.Report_XHD_print(XHDH); DSXHDP = BASEINFO.DecompressDS(b); DSXHDP.Tables[0].TableName = "Command"; REPORT.XHprint xhPRINT = new POS.REPORT.XHprint(); if (ps.IsValid && ps.IsDefaultPrinter) { int i = -1; foreach (PaperSize pas in ps.PaperSizes) { if (pas.PaperName == "XH_P") { i = pas.RawKind; break; } } if (i == -1)//如果沒有找到自定義紙張,添加自定義紙張 { SetPaperSize("XH_P", 1200, 1800); foreach (PaperSize pas in ps.PaperSizes) { if (pas.PaperName == "XH_P") { i = pas.RawKind; break; } } } pp.crystalReportViewer1.ReportSource = xhPRINT;
PrintPreview pp = new PrintPreview();
Form w = new waiting();
try
{
w.Show();
DataSet DSXHDP = new DataSet();
byte[] b = POS.Report_XHD_print(XHDH);
DSXHDP = BASEINFO.DecompressDS(b);
DSXHDP.Tables[0].TableName = "Command";
REPORT.XHprint xhPRINT = new POS.REPORT.XHprint();
if (ps.IsValid && ps.IsDefaultPrinter)
{
int i = -1;
foreach (PaperSize pas in ps.PaperSizes)
{
if (pas.PaperName == "XH_P")
{
i = pas.RawKind;
break;
}
}
if (i == -1)//如果沒有找到自定義紙張,添加自定義紙張
{
SetPaperSize("XH_P", 1200, 1800);
foreach (PaperSize pas in ps.PaperSizes)
{
if (pas.PaperName == "XH_P")
{
i = pas.RawKind;
break;
}
}
}
pp.crystalReportViewer1.ReportSource = xhPRINT;
xhPRINT.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)i;
}
// pp.crystalReportViewer1.ReportSource = xhPRINT;
xhPRINT.SetDataSource(DSXHDP.Tables[0]);
xhPRINT.SetParameterValue("FKJE", SS);
xhPRINT.SetParameterValue("ZHJE", ZH);
xhPRINT.SetParameterValue("GKXM", "");
xhPRINT.SetParameterValue("GTBHMC", "");
pp.Show();
//xhPRINT.PrintToPrinter(1, false, 0, 0);//直接送到打印機
}
catch
{
MessageBox.Show("打印補中斷,請檢查印表機");
}
finally
{
w.Close();
}
}