1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
using System.Runtime.InteropServices;
...
private Image _memImage;
...
#region gdi322.dll
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int xDest, // x coord of the dest upper left corner
int yDest, // y coord of the dest upper left corner
int width, // width of the destination rectangle
int height, // height of the destination rectangle
IntPtr hdcSrc, // handle to source DC
int xSrc, // x coord of the source upper left corner
int ySrc, // y coord of the source upper left corner
Int32 dwRop // raster operation code
);
#endregion
...
#region main menu imprimer
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
// Rafraichit le Form pour ne pas capturer l'animation du menu
this.Refresh();
Graphics g = this.CreateGraphics();
Size s = this.Size;
_memImage = new Bitmap(s.Width, s.Height, g);
Graphics memGraphic = Graphics.FromImage(_memImage);
IntPtr dc1 = g.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g.ReleaseHdc();
memGraphic.ReleaseHdc();
// Show the print dialog
PrintDialog pd = new PrintDialog();
pd.Document = printDocument1;
DialogResult dr = pd.ShowDialog();
if (dr == DialogResult.OK)
{
printDocument1.Print();
}
}
#endregion
#region Event Print Page
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(_memImage, 0, 0);
}
#endregion |
Partager