Winform 单击打印事件
private void btnPrint_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows[0].Cells[0].Value != null)
{
try
{
DGVPrinter printer = new DGVPrinter();
printer.Title = txtClient.Text;
printer.SubTitle = "200 IP电话 话费清单";
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit |
StringFormatFlags.NoClip;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
//printer.Footer = "Your Company Name Here";
printer.FooterSpacing = 5;
printer.PrintDataGridView(dataGridView1);
}
catch { MessageBox.Show("请选择打印机"); }
}
else
MessageBox.Show("请插入数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
DGVPrinter 类下载地址:
http://file.ddvip.com/2010_03/1269920799_ddvip_6521.zip
效果图如下: