怎么打印ListView或者DataGirdView?      最好是有代码!!!
                

解决方案 »

  1.   

    http://blog.csdn.net/liang4571231/archive/2008/09/29/2997943.aspx
    关于打印DataGirdView详细代码
      

  2.   

    private void button2_Click(object sender, EventArgs e) 
            {             PrintPreviewDialog ppd = new PrintPreviewDialog(); 
                PrintDocument pd = new PrintDocument(); 
                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); 
                ppd.Document = pd; 
                ppd.ShowDialog(); 
            }         void pd_PrintPage(object sender, PrintPageEventArgs e) 
            { 
              // throw new Exception("The method or operation is not implemented."); 
              // e.Graphics.MeasureString(text, ft); 测量列宽,找出最大的列宽,在一个矩形中进行打印并居中 
                // e.Graphics.DrwLine()  ;画线 
                float ypos = 0; 
                float leftMargin = e.MarginBounds.Left; 
                float topMargin = e.MarginBounds.Top; 
                //---计算每一页有多少行数据 
                int linePerPage = (int)(e.MarginBounds.Height / ft.GetHeight(e.Graphics)); 
                int count = 0;  
                int pageNo = 0; //要设全局的变量
                int lineNo = pageNo * linePerPage;             ypos = topMargin; 
                while (count < linePerPage && lineNo < listview 总共有多少行 ) 
                { 
                    ypos += ft.GetHeight(e.Graphics); 
                    e.Graphics.DrawString(“listview一行的内容” , ft, Brushes.Black, leftMargin, ypos, 
                   new  StringFormat()); 
                    
                  
                    count++; 
                    lineNo++; 
                } 
                if(lineNo <listview 总共有多少行 ) 
                    e.HasMorePages =true; 
                else 
                    e.HasMorePages =false; 
                pageNo ++;
            }