111,098
社区成员




public bool Print()
{
bool bolIsSuccess = false;
PrintDocument pd = new PrintDocument();
PaperSize ps = new PaperSize("Measure", 350, 650);
pd.DefaultPageSettings.PaperSize = ps;
pd.DefaultPageSettings.PrinterSettings.Copies = 1;
pd.DefaultPageSettings.PrinterSettings.MaximumPage = 1;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
bolIsSuccess = true;
return bolIsSuccess;
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Font titleFont = new Font("宋体", 14, FontStyle.Bold);//标题字体
Font fntTxt = new Font("宋体", 12, FontStyle.Regular);//正文文字
Brush brush = new SolidBrush(Color.Black);//画刷
Pen pen = new Pen(Color.Black); //线条颜色
Point poTitle = new Point(40, 200);
Point poTime = new Point(70, 210);
Point poTxt = new Point(20, 235);
StringBuilder sb = GetPrintSW();
string strTime = DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日 " + DateTime.Now.ToString("HH:mm:ss");
try
{
e.Graphics.DrawString("\r\n\r\n\r\n\r\n\r\n\r\nXXXXXXX计量单", fntTxt, new SolidBrush(Color.White), new Point(45,100));
e.Graphics.DrawString("\r\n\r\n\r\n\r\n\r\n\r\nXXXXXXXX计量单", fntTxt, brush, poTitle);
e.Graphics.DrawString("\r\n\r\n\r\n\r\n\r\n\r\n\r\n"+strTime, fntTxt, brush, poTime);
e.Graphics.DrawString(sb.ToString(), fntTxt, brush, poTxt); //DrawString方式进行打印。
if (dt.Rows.Count > 0)
{
string strMeaDocId = dt.Rows[0]["C_MeasureDocID"].ToString() ?? "";
if (!string.IsNullOrEmpty(strMeaDocId))
{
barcodeControl.Data = strMeaDocId;
}
}
barcodeControl.CopyRight = "";
BarcodeType bt = BarcodeType.CODE39;
barcodeControl.BarcodeType = bt;
Graphics g = e.Graphics;
Rectangle rect = barcodeControl.ClientRectangle;
rect = new Rectangle(90, 550, 230, 50);
//打印
barcodeControl.Draw(g, rect, GraphicsUnit.Inch, 0.01f, 0, null);
g.Dispose();
}
catch (Exception ex)
{
SaveLog.SaveErrLog("打印小票出错:"+ex.Message);
return;
}
}