打印dataGridView中的数据

//执行打印窗体中的数据操作

private void toolStripButton2_Click(object sender, EventArgs e)
{

printDialog1.ShowDialog(); //设置打印文档
printPreviewDialog1.Document = this.printDocument1;
printPreviewDialog1.ShowDialog();
}

//在窗体中绘制要打印的数据

private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
//e.Graphics.DrawString(dataGridView1.Columns.ToString(), new Font("宋体", 10, FontStyle.Regular), Brushes.Black, 260, 400);

int r = 0;
int c = 20;
for(int i=0;i<dt.Rows.Count;i++)
{

for(int j=0;j<dt.Columns.Count;j++)
{

e.Graphics.DrawString(dt.Rows[i][j].ToString(), new Font("宋体", 10, FontStyle.Regular), Brushes.Black, r, c);
r = r + 60;

}
r = 0;
c += 20;

}
}

你可能感兴趣的:(C++,c,C#,J#)