C# 热敏打印机小问题
这个问题出现的几率不大。出现的时候打印只能打印一行数据,下面的内容都不出现。有时候多打印几次就好了,不知道为什么,但是加上预览之后就不出现了。请各位大侠指教。下面是代码:private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
MyPrint1(e.Graphics);
}
private void MyPrint1(Graphics g)
{
try
{
Pen pen = new Pen(Brushes.Black);
Font font = new Font("宋体", 10);
Font titleFont = new Font("宋体", 16, FontStyle.Bold);
//写字
//// g.DrawImage(pictureBox2.Image, 40, 5,100, 40);
string company = "";
DataSet ds = departmentBll.GetList(" isdeleted ='root'");
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
company = ds.Tables[0].Rows[0]["Sname"].ToString();
}
g.DrawString(company, font, Brushes.Black, new RectangleF(5, 5, 400, 20));
g.DrawLine(pen, new Point(0, 25), new Point(400, 25));
VisitorInfo VImodel = TempVI;
if (TempVI.Picture != null && TempVI.Picture.Length != 0)
{
g.DrawImage(GetImageByByteArray(VImodel.Picture), 40, 40, 100, 123);
}
else if (TempVI.VisitorPicture != null && TempVI.VisitorPicture.Length != 0)
{
g.DrawImage(GetImageByByteArray(VImodel.VisitorPicture), 40, 40, 100, 123);
}
else
{
g.DrawImage(GetImageByByteArray(Peric.ISMSIRA.Common.CommonCL.ImageUtil.BitmapToBytes
(Peric.ISMSIRA.VMSM.Properties.Resources.wu)), 40, 40, 100, 123);
}
g.DrawString("访客姓名:" + VImodel.Name, font, Brushes.Black, new RectangleF(5, 170, 400, 20));
g.DrawString("访客性别:" + VImodel.Sex, font, Brushes.Black, new RectangleF(5, 190, 600, 50));
g.DrawString("同行人数:" + VImodel.VisitorNum, font, Brushes.Black, new RectangleF(5, 210, 600,
50));
g.DrawString("登记地点:" + VImodel.RegistAddress, font, Brushes.Black, new RectangleF(5, 230, 600,
50));
g.DrawString("访客单位:" + VImodel.Company, font, Brushes.Black, new RectangleF(5, 250, 600, 50));
string[] workerNames = VImodel.WorkerName.Split('、');//被访人姓名的名称数组;
string[] workerDepartments = VImodel.WDepartName.Split('、');//被访人所属部门的数组;
g.DrawString("被 访 人:" + workerNames[0], font, Brushes.Black, new RectangleF(5, 270, 600, 50));
int y = 270;
if (workerNames != null && workerNames.Length > 1)
{
for (int i = 1; i < workerNames.Length; i++)
{
y += 30;
g.DrawString(workerNames[i], font, Brushes.Black, new RectangleF(74, y, 600, 50));
}
}
y += 30;
g.DrawString("被访部门:" + workerDepartments[0], font, Brushes.Black, new RectangleF(5, y, 600,
50));
if (workerDepartments != null && workerDepartments.Length > 1)
{
for (int i = 1; i < workerDepartments.Length; i++)
{
y += 30;
g.DrawString(workerDepartments[i], font, Brushes.Black, new RectangleF(74, y, 600, 50));
}
}
y += 30;
g.DrawString("来访时间:" + VImodel.VisitTime.ToString().Substring(0, VImodel.VisitTime.ToString
().LastIndexOf(':')), font, Brushes.Black, new RectangleF(5, y, 600, 50));
y += 30;
g.DrawString("备注信息:" + VImodel.Comment, font, Brushes.Black, new RectangleF(5, y, 600, 50));
y += 30;
g.DrawString("被访人签名:", font, Brushes.Black, new RectangleF(5, y, 200, 50));
b.IncludeLabel = true;
Image img = b.Encode(BarcodeLib.TYPE.CODE39, VImodel.V_No, Color.Black, Color.White, 180, 50);
y += 20;
g.DrawImage(img, 0, y);
y += 80;
g.DrawString("请妥善保管,离开交还门卫", font, Brushes.Black, new RectangleF(5, y, 200, 50));
}
catch (Exception ex)
{
CommonFunctionClass.ShowMessage("打印时出错,请检查打印设备是否已正确连接");
}
} --------------------编程问答-------------------- 有没有人知道啊
补充:.NET技术 , C#