Essai ça:
[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, 50, 50, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 50, 50, 13369376); mygraphics.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); }
private void button1_Click(object sender, System.EventArgs e) { PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = printDocument1; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { CaptureScreen(); printDocument1.Print(); } }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(memoryImage, 50, 50); }
normalement ça marche
|