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
|
[ System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll" ) ]
private static extern bool BitBlt( IntPtr hdcDest,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
IntPtr hdcSrc,
int nXSrc,
int nYSrc,
System.Int32 dwRop );
private void button1_Click(object sender, System.EventArgs e)
{
PrintDialog foo = new PrintDialog();
foo.Document = printDocument1;
DialogResult res = foo.ShowDialog();
if ( res == DialogResult.OK )
{
printDocument1.Print();
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphicsSrc = this.CreateGraphics();
Image image = new Bitmap( this.Size.Width, this.Size.Height );
Graphics graphicsDst = Graphics.FromImage( image );
IntPtr srcDC = graphicsSrc.GetHdc();
IntPtr dstDC = graphicsDst.GetHdc();
BitBlt( dstDC, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, srcDC, 0, 0, 13369376 );
graphicsSrc.ReleaseHdc( srcDC );
graphicsDst.ReleaseHdc( dstDC );
e.Graphics.DrawImage( image, 0, 0 );
}
|