private void CaptureScreen()
{
Graphics mygraphics = this.panel1.CreateGraphics();
Size s = this.panel1.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
} private void Printbutton_Click(object sender, System.EventArgs e)
{
System.Drawing.Printing.PrintDocument pd =new PrintDocument();

CaptureScreen();
pd.PrintPage +=new PrintPageEventHandler(pd_PrintPage);
PrintPreviewDialog printPreviewDialog1 =new PrintPreviewDialog ();
printPreviewDialog1.Document =pd;
printPreviewDialog1.ShowDialog() ;
pd.DocumentName = "堆芯图";
pd.OriginAtMargins = true;
pd.Print();
}
private void pd_PrintPage(object sender,PrintPageEventArgs ev)
{
ev.Graphics.DrawImage(memoryImage, 0, 0); }这样只能截到满屏的啊

解决方案 »

  1.   

    给你一个建议,就是把你在Panel上画的图在Bitmap里也画一遍,然后你打印bitmap就好了。
      

  2.   

    abcynic(门外汉):
    在Bitmap如何画?
      

  3.   

    what's in memoryImage? don't use screen capture, just draw the stuffs in your panel in  pd_PrintPage
      

  4.   

    How can i draw the stuffs in my panel in  pd_PrintPage?
      

  5.   

    >>>我的窗口上有一个Panel,我在里面画了一些图形same way you draw those 图形, don't keep them in a data structure so you can redraw them in OnPaint?
      

  6.   

    Yes.I draw the graphics in event handler -- OnPaint.
    And how can i create a bitmap and draw the same in it ?