我想在 A4 大小的页面中打印 datagridview。我成功地能够打印预览第一页,但无法从第二页打印或预览。我正在提交代码。
Private void printDocument1_PrintPage(object sender,system.Drawing.Printing.PrintPageEventArgs e)
{
int rowcounter=0;
int x=0;
int rowheight=0;
int colwidth=0;
rowheight=dataGridView1.Rows[0].Height;
colwidth=dataGridView1.Columns[1].width;
for(int i=1;i<dataGridView1.Columns.count;i++)
{ e.Graphics.DrawReactangle(Pens.Black,x,0,colwidth,20);
e.Graphics.FillReactangle(Brushes.LightGray,x,0,colwidth,20);
e.Graphics.Drawstring(dataGridView1.Columns[i].HeaderText.ToString(),dataGridView1.Font,Brushes.Black,new ReactangleF(x,0,colwidth,20));
x=x+colwidth;
}
While(rowcounter<=dataGridView1.Rows.Count-1)
{
int y=0;
int j=0;
int i;
int xaxis=20;
rowheight=dataGridview1.Rows[0].Height;
colwidth=dataGridview1.Columns[1].width;
for(j=0;j<=dataGridView1.Rows.Count-1;j++)
{
for(i=1;i<dataGridView1.Columns.Count;i++)
{
e.Graphics.DrawReactangle(Pens.Black,y,xaxis,colwidth,dataGridView1.Rows[j].Height);
e.Graphics.Drawstring(dataGridView1.Rows[j].cells[i].Value.ToString(),dataGridView1.Font,Brushes.Black,new ReactangleF(y,xaxis,colwidth,dataGridView1.Rows[j].Height));
y=y+colwidth;
}
xaxis=xaxis+dataGridView1.Rows[j].Height;
y=0;
}
rowcount++;
}
}
Private Void button6_Click(object sender,EventArgs e)
{
printPreViewDialog1.Document=printDocument1;
printPreViewDialog1.ShowDialog();
}
请帮我......
谢谢。