用小票打印机打印
2009-10-21 14:22
363 查看
用小票打印机打印datagridview内容。
引用using System.Drawing.Printing;
在winform中添加printDocument1控件,
添加printDocument1的PrintPage的事件printDocument1_PrintPage
void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//从数据源中得到数据表对象
DataTable dt = (DataTable)dataGridView1.DataSource;
//设置初始打印位置及打印位置递增量
int x = 30, y = 0, kuan = 70, gao = 25;
//设置字体对象
Font ff = new Font("宋体", 10);
//打印“学生表”三个字
//e.Graphics.DrawString("学生表", ff, Brushes.Blue, x, y);
//打印的行向下一行
y += gao;
//使用循环打印出数据表的列名
//foreach (DataColumn column in dt.Columns)
//{
// //开始打印列
// e.Graphics.DrawString(column.ColumnName, ff, Brushes.Black, x, y);
// //行宽自动增加
// x += kuan;
//}
//向下一行
y += gao;
//回到行头
x = 30;
//使用循环打印数据表中的内容
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
//打印
e.Graphics.DrawString((string)dt.Rows[i].ItemArray[j].ToString(), ff, Brushes.Black, x, y);
//打印一行后,宽度自动变化
x += kuan;
}
//打印一行后,宽度自动归零
x = 30;
//打印一行后,行自动向下加一行
y += gao;
}
}
调用方法:
printDocument1.Print();
即可
引用using System.Drawing.Printing;
在winform中添加printDocument1控件,
添加printDocument1的PrintPage的事件printDocument1_PrintPage
void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//从数据源中得到数据表对象
DataTable dt = (DataTable)dataGridView1.DataSource;
//设置初始打印位置及打印位置递增量
int x = 30, y = 0, kuan = 70, gao = 25;
//设置字体对象
Font ff = new Font("宋体", 10);
//打印“学生表”三个字
//e.Graphics.DrawString("学生表", ff, Brushes.Blue, x, y);
//打印的行向下一行
y += gao;
//使用循环打印出数据表的列名
//foreach (DataColumn column in dt.Columns)
//{
// //开始打印列
// e.Graphics.DrawString(column.ColumnName, ff, Brushes.Black, x, y);
// //行宽自动增加
// x += kuan;
//}
//向下一行
y += gao;
//回到行头
x = 30;
//使用循环打印数据表中的内容
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
//打印
e.Graphics.DrawString((string)dt.Rows[i].ItemArray[j].ToString(), ff, Brushes.Black, x, y);
//打印一行后,宽度自动变化
x += kuan;
}
//打印一行后,宽度自动归零
x = 30;
//打印一行后,行自动向下加一行
y += gao;
}
}
调用方法:
printDocument1.Print();
即可
相关文章推荐
- 餐饮外卖小程序如何对接小票打印机自动接单打印
- 用POS小票打印机,用GDI+做打印好还是用水晶报表好
- 有赞打印机如何批量打印订单小票?如何打印二维码
- 美团,饿了么,百度打印机如何自动打印外卖订单小票(教程)
- 外卖云打印机如何设置智能打印小票底部logo
- Android打印机--小票打印格式及模板设置实例代码
- C# 热敏打印机 小票打印机 打印图片
- 【转】C#使用ESC指令控制POS打印机打印小票
- 按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式
- C# 热敏打印机 小票打印机 打印图片
- iOS socket连接打印机打印小票
- C#使用ESC指令控制POS打印机打印小票
- java实现热敏打印机打印小票
- 按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式
- 手把手教,你如何设置超市小票打印机打印票据(图文教程)
- C# 热敏打印机 小票打印机 打印图片
- C# 网络打印机ESC指令打印小票
- android端StarIO热敏打印机打印小票
- Android打印机--小票打印格式及模板设置
- 微信支付小票打印机如何打印收付款二维码(教程)