我正在做条形码的打印.
panel里有Label控件多个,一个条形码图片,现在我想按照Panel里的位置打印出来.
我单独印一个(Label或条形码图片)就可以,请问怎样一次打印完要打印的控件呢??
代码如下:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{ e.Graphics.DrawImage(BC.Image(3500, 750), e.PageSettings.Margins.Left, e.PageSettings.Margins.Top, 350, 75); e.HasMorePages=false; }
private void Print_Click(object sender, System.EventArgs e)
{
try 
{ printDocument1.Print();
}  
catch(Exception ex) 
{
MessageBox.Show(ex.ToString(), "An error occurred while printing");
} }

解决方案 »

  1.   

    我这有个办法,你参考一下 
    private void btnPrint_Click(object sender, System.EventArgs e) 
          { 
             Graphics graphic = panelReports.CreateGraphics();  
             Size s = panelReports.Size;  
             Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);  
             Graphics memGraphic = Graphics.FromImage(memImage);  
             IntPtr dc1 = graphic.GetHdc();  
             IntPtr dc2 = memGraphic.GetHdc();  
             BitBlt(dc2, 0, 0, panelReports.ClientRectangle.Width, panelReports.ClientRectangle.Height,  
                dc1, 0, 0, 13369376);  
              
             //Clone   the bitmap so we can dispose it. 
             print_image = (Image)memImage.Clone(); 
             graphic.ReleaseHdc(dc1); 
             memGraphic.ReleaseHdc(dc2); 
             graphic.Dispose(); 
             memGraphic.Dispose(); 
             memImage.Dispose();          PrintPreviewDialog dlg = new PrintPreviewDialog() ; 
             dlg.Width = 800; 
             dlg.Height = 600; 
             dlg.Document = printDocument1; 
             if (dlg.ShowDialog() == DialogResult.OK) 
                printDocument1.Print(); 
          } 
    panelReports是panel的name 
      

  2.   

    TO: binny0532Thanks~我试试看~~