using System;
using System.Drawing;
using System.Windows.Forms;
namespace PrintWindowForm
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr Dest, int Xaxes, int Yaxes,
int Width, int Height, IntPtr Src, int XSrcaxes, intYSrcaxes, int dwRop);
private Bitmap myBitmap;
System.Drawing.Printing.PrintDocument myPrintDocument
=
new System.Drawing.Printing.PrintDocument();
public Form1()
{
InitializeComponent();
}
private void myPrintDocument_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(myBitmap, 0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
Graphics myGraphics1
= this.CreateGraphics();
myBitmap = new Bitmap(this.Width, this.Height, this.CreateGraphics());
Graphics myGraphics2
= Graphics.FromImage(myBitmap);
IntPtr HandleDeviceContext1
= myGraphics1.GetHdc();
IntPtr HandleDeviceContext2
= myGraphics2.GetHdc();
BitBlt(HandleDeviceContext2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height,
HandleDeviceContext1, 0, 0, 13369376);
myGraphics1.ReleaseHdc(HandleDeviceContext1);
myGraphics2.ReleaseHdc(HandleDeviceContext2);
myPrintDocument.PrintPage +=
new System.Drawing.Printing.PrintPageEventHandler(myPrintDocument_PrintPage);
myPrintDocument.Print();
}
}
} |