高分求高手指点!!打印Panel控件中的所有内容???(问题解决就给分,不够再加!!)
在Panel控件中,有条形码(BarcodeControl)控件和pictureBox控件和一个Label,这三个组合在Panel控件中,我要把Panel控件的这些控件内容都打印和保存下来,代码该怎么写???
我自己写了点打印的,一直不对~~~~~
那为高手指点下!!!!!
private void SaveButton2_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
PrintPreviewDialog cppd = new PrintPreviewDialog();
cppd.Document = pd;
cppd.ShowDialog();
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = panel1.CreateGraphics();
Size s = panel1.Size;
Bitmap b = new Bitmap(s.Width, s.Height, g);
Graphics g2 = Graphics.FromImage(b);
IntPtr dc1 = g.GetHdc();
IntPtr dc2 = g2.GetHdc();
g.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
g.Dispose();
g2.Dispose();
}
------解决方案--------------------[System.Runtime.InteropServices.DllImport( "gdi32.dll ")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.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 printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memory