private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int_yema++;
Graphics g=e.Graphics;
int LinePages=0;
int count=0;
int all_width=0;
for(int i=0;i<this.listView1.Columns.Count;i++)
{
if(this.listView1.Columns[i].Width>10)
all_width+=this.listView1.Columns[i].Width;
}
float LeftMargin=(e.PageBounds.Width-all_width)/2;
float TopMargin=100.0f;
float Bottom=e.MarginBounds.Height+40;
float []colleft=new float[this.listView1.Columns.Count+1];
for(int i=0;i<this.listView1.Columns.Count+1;i++)
{
if(i==0)
colleft[i]=LeftMargin;
else
{
if(this.listView1.Columns[i-1].Width>10)
colleft[i]=colleft[i-1]+this.listView1.Columns[i-1].Width;
else
colleft[i]=colleft[i-1];
}
}
float line_high=22;
LinePages=(int)((e.MarginBounds.Height)/line_high);//一页 的行数
///上面是固定的列以及宽度
System.Drawing.SizeF str_size=g.MeasureString(YSZS.Global.Year.ToString().Trim()+"年"+"文化成绩核对报表",new Font(this.Font.ToString(),15.0f),e.MarginBounds.Width,new StringFormat());
float t=(e.PageBounds.Size.Width-str_size.Width)/2;
g.DrawString(YSZS.Global.Year.ToString().Trim()+"年"+"文化成绩核对报表",new Font(this.Font.ToString(),15.0f),Brushes.Black,t,50.0f,new StringFormat());
g.DrawLine(Pens.Black,LeftMargin,TopMargin,colleft[this.listView1.Columns.Count],TopMargin);
for(int i=0;i<this.listView1.Columns.Count;i++)
{
if(this.listView1.Columns[i].Width>10)
g.DrawString(this.listView1.Columns[i].Text.ToString(),this.Font,Brushes.Black,colleft[i]+4,TopMargin+3,new StringFormat());
}
g.DrawLine(Pens.Black,LeftMargin,TopMargin+line_high,colleft[this.listView1.Columns.Count],(float)TopMargin+line_high);
for( ;now_line<this.listView1.Items.Count;now_line++)
{
for(int j=0;j<this.listView1.Columns.Count;j++)
{
string line;
line=this.listView1.Items[now_line].SubItems[j].Text;
if(this.listView1.Columns[j].Width>10)
g.DrawString(line,this.Font,Brushes.Black,colleft[j]+4,TopMargin+line_high+count*line_high+3,new StringFormat());
}
g.DrawLine(Pens.Black,(float)colleft[0],(float)TopMargin+2*line_high+line_high*count,(float)colleft[this.listView1.Columns.Count],(float)TopMargin+2*line_high+line_high*count);
count++;
if(count>=LinePages)
{
now_line++;
break;
}
}
for(int colindex=0;colindex<this.listView1.Columns.Count+1;colindex++)
{
g.DrawLine(Pens.Black,(float)colleft[colindex],TopMargin,(float)colleft[colindex],(float)TopMargin+2*line_high+line_high*(count-1));
}
g.DrawString("第"+int_yema+"页"+System.DateTime.Now.ToShortDateString(),this.Font,Brushes.Black,e.MarginBounds.Width-150,e.MarginBounds.Height+100+30,new System.Drawing.StringFormat() );
if(now_line<this.listView1.Items.Count)
e.HasMorePages=true;
else
e.HasMorePages=false;
}