C#图片格式打印
2011-05-26 17:28
141 查看
#region 打印
private void btnPrint_Click(object sender, EventArgs e)
{
//打印预览
//PrintPreviewDialog ppd = new PrintPreviewDialog();
PrintDocument pd = new PrintDocument();
//设置边距
Margins margin = new Margins(20, 20, 20, 20);
pd.DefaultPageSettings.Margins = margin;
////纸张设置默认
//PaperSize pageSize = new PaperSize("First custom size", 800, 600);
//pd.DefaultPageSettings.PaperSize = pageSize;
//打印事件设置
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
//ppd.Document = pd;
//ppd.ShowDialog();
try
{
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
pd.PrintController.OnEndPrint(pd, new PrintEventArgs());
}
}
//打印事件处理
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
string date = lblDate.Text; //当前日期
string flowId = lblFlowId.Text; //流水号
string payDate = PayDate.Year.ToString() + "年" + PayDate.Month.ToString() + "月"; //应收年月
string adminId = lblAdminId.Text; //操作员编号
string baseExpense = lblBaseExpense.Text; //应交基本费用
string fine = lblFine.Text; //罚款数目
string upExpense = lblUpExpense.Text; //上月上余
string actualExpense = txtActualExpense.Text; //实际应交费用
string chineseExpense = DecimalToChinese.ConvertSum(actualExpense); //实际应交费用的中文大写
//读取图片模板
Image temp = Image.FromFile(@"Receipts.jpg");
GetResultIntoImage(ref temp, UserId, flowId, date, baseExpense, fine, upExpense, actualExpense, chineseExpense, payDate, adminId);
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = temp.Width;
int height = temp.Height;
Rectangle destRect = new Rectangle(x, y, width, height);
e.Graphics.DrawImage(temp, destRect, 0, 0, temp.Width, temp.Height, System.Drawing.GraphicsUnit.Pixel);
}
/// <summary>
/// 将收费结果填充到图片模板
/// </summary>
private void GetResultIntoImage(
ref Image temp,
string userId,
string flowId,
string currentDate,
string baseExpense,
string fine,
string upExpense,
string actualExpense,
string chineseExpense,
string payDate,
string adminName)
{
//读取图片模板
Graphics g = Graphics.FromImage(temp);
Font f = new Font("宋体", 12);
Brush b = new SolidBrush(Color.Black);
//填充数据到图片模板(位置要在制作图片模板的时候度量好)
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
g.DrawString(userId, f, b, 168, 105);
g.DrawString(UserName, f, b, 166, 134);
g.DrawString(flowId, f, b, 535, 105);
g.DrawString(currentDate, f, b, 535, 134);
g.DrawString(baseExpense, f, b, 219, 202);
g.DrawString(fine, f, b, 372, 202);
g.DrawString(upExpense, f, b, 486, 202);
g.DrawString(actualExpense, f, b, 596, 202);
g.DrawString(chineseExpense, f, b, 196, 238);
g.DrawString(payDate, f, b, 176, 269);
g.DrawString(adminName, f, b, 497, 298);
g.Dispose();
}
#endregion
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xujuntao0000/archive/2010/08/25/5836837.aspx
private void btnPrint_Click(object sender, EventArgs e)
{
//打印预览
//PrintPreviewDialog ppd = new PrintPreviewDialog();
PrintDocument pd = new PrintDocument();
//设置边距
Margins margin = new Margins(20, 20, 20, 20);
pd.DefaultPageSettings.Margins = margin;
////纸张设置默认
//PaperSize pageSize = new PaperSize("First custom size", 800, 600);
//pd.DefaultPageSettings.PaperSize = pageSize;
//打印事件设置
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
//ppd.Document = pd;
//ppd.ShowDialog();
try
{
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
pd.PrintController.OnEndPrint(pd, new PrintEventArgs());
}
}
//打印事件处理
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
string date = lblDate.Text; //当前日期
string flowId = lblFlowId.Text; //流水号
string payDate = PayDate.Year.ToString() + "年" + PayDate.Month.ToString() + "月"; //应收年月
string adminId = lblAdminId.Text; //操作员编号
string baseExpense = lblBaseExpense.Text; //应交基本费用
string fine = lblFine.Text; //罚款数目
string upExpense = lblUpExpense.Text; //上月上余
string actualExpense = txtActualExpense.Text; //实际应交费用
string chineseExpense = DecimalToChinese.ConvertSum(actualExpense); //实际应交费用的中文大写
//读取图片模板
Image temp = Image.FromFile(@"Receipts.jpg");
GetResultIntoImage(ref temp, UserId, flowId, date, baseExpense, fine, upExpense, actualExpense, chineseExpense, payDate, adminId);
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = temp.Width;
int height = temp.Height;
Rectangle destRect = new Rectangle(x, y, width, height);
e.Graphics.DrawImage(temp, destRect, 0, 0, temp.Width, temp.Height, System.Drawing.GraphicsUnit.Pixel);
}
/// <summary>
/// 将收费结果填充到图片模板
/// </summary>
private void GetResultIntoImage(
ref Image temp,
string userId,
string flowId,
string currentDate,
string baseExpense,
string fine,
string upExpense,
string actualExpense,
string chineseExpense,
string payDate,
string adminName)
{
//读取图片模板
Graphics g = Graphics.FromImage(temp);
Font f = new Font("宋体", 12);
Brush b = new SolidBrush(Color.Black);
//填充数据到图片模板(位置要在制作图片模板的时候度量好)
g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
g.DrawString(userId, f, b, 168, 105);
g.DrawString(UserName, f, b, 166, 134);
g.DrawString(flowId, f, b, 535, 105);
g.DrawString(currentDate, f, b, 535, 134);
g.DrawString(baseExpense, f, b, 219, 202);
g.DrawString(fine, f, b, 372, 202);
g.DrawString(upExpense, f, b, 486, 202);
g.DrawString(actualExpense, f, b, 596, 202);
g.DrawString(chineseExpense, f, b, 196, 238);
g.DrawString(payDate, f, b, 176, 269);
g.DrawString(adminName, f, b, 497, 298);
g.Dispose();
}
#endregion
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xujuntao0000/archive/2010/08/25/5836837.aspx
相关文章推荐
- C#图片格式打印
- 在Tif图片格式中如何设置打印部分页数
- 在Tif图片格式中如何设置打印部分页数
- webview加载html格式带图片的数据
- pdflatex 插入 EPS 格式图片的两种方法_极夜•潜_百度空间
- GDIplus的初次接触--加载并显示常用格式图片
- 使IE6正常显示PNG-24格式图片代码
- Android图片操作-保存图片格式
- 手机待机图片格式详细解说
- 图片格式:RAW
- 在sap系统设置纸张打印格式
- 利用PhotoShop将Font-Awesome转为图片格式
- WEB开发常用的图片格式
- Ora-01830 日期格式图片在转换整个输入字符串之前结束
- UIImage和Base64格式图片相互转化!
- 利用CImage完成图片的显示、拷贝、绘制及转换图片格式
- js 下载Base64格式数据图片(兼容主流浏览器)
- Qt 打印图片
- 几种常见图片文件格式的优缺点
- C#下怎样处理并保存单色格式PNG图片?