To create the Print Out, you will have to write to your PrintDocument using GDI. There is nothing really built in. You could possibly do a screenshot (code below).
Exporting data to CSV is best done on your own as well. Just Create/Open a file stream and write whatever you want to it.
Screenshot: Requires PInvoke to BitBlt and GetDC
const int SRCCOPY = 0x00CC0020;
[DllImport("coredll.dll")]
private static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("coredll.dll")]
private static extern IntPtr GetDC(IntPtr hwnd);
public Bitmap ScreenCapture(string fileName) {
Bitmap bitmap = new Bitmap(this.Width, this.Height);
using (Graphics gScr = Graphics.FromHdc(GetDC(IntPtr.Zero))) { // A Zero Pointer will Get the screen context
using (Graphics gBmp = Graphics.FromImage(bitmap)) { // Get the bitmap graphics
BitBlt(gBmp.GetHdc(), 0, 0, this.Width, this.Height, gScr.GetHdc(), this.Left, this.Top, SRCCOPY); // Blit the image data
}
}
bitmap.Save(fileName, ImageFormat.Png); //Saves the image
return bitmap;
}
[Update]:
If you want the image saved to a particular location, send the full path with the filename (i.e. \WindowsTempscreenShot.png
).
If you want to exclude the controls, reduce the this.Width
, this.Height
, this.Left
and this.Right
until you have the size that fits the region that works.
Last, if you want the Bitmap
to use in memory, simply save it and use it as necessary. Example:
panel1.Image = ScreenCapture("image.png");
panel1.BringToFront();
Hope that helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…