listview打印基础

 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;
  
  } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值