winform源码下载
⑴ 求winform套打源码 小弟穷就56财富 只能给50了 求高手帮忙
PrintDocument pd = new PrintDocument();
//设置边距
Margins margin = new Margins(20, 20, 20, 20);
pd.DefaultPageSettings.Margins = margin;
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
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 = DateTime.Now.ToString(); //当前日期
string flowId = "A0000-00001"; //流水号
string payDate = DateTime.Now.ToString("yyyy年MM月"); //应收年月
string adminId = "A-01"; //操作员编号
string baseExpense = "50.00"; //应交基本费用
string fine = "30.00"; //罚款数目
string upExpense = "-20.00"; //上月上余
string actualExpense = "50.00"; //实际应交费用
string chineseExpense = "伍十圆整"; //实际应交费用的中文大写
//读取图片模板
Image temp = Image.FromFile(@"Receipts.jpg");
GetResultIntoImage(ref temp, "1", 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("Admin", 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();}
自己把需要打印纸的大小 做一张同样大小 空白的图片 这里我使用的是图片进行打印 打印的数据乃是使用在图片上面进行坐标控制 等第一张打出来了 其余的慢慢调下就好了