This works well:
Add a PrintDocument, PrintPreview to your form. Set the PrintPreviews
document property to the PrintDocument, and set the PrintDocuments
PrintPage procedure to the pd_PrintPage item below. This code presumes
a PrintDocument named Pd, a print preview named ppv, and a print button
named cmPrintForm. You'll have to adjust the scaling and other factors
to fit your form, and generally make this your own. This is for the
purpose of printing your actual form as the user sees it. I owe credit
to Lion Shi for originally posting this code.
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
Int32 dwRop // raster operation code
);
private Bitmap memoryImage;
private void CaptureScreen() {
string myUser =
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(System.Environment.UserName.ToLower());
System.Drawing.Font mFont = new System.Drawing.Font("Arial", 12);
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
string strOne = "Add Style or Component Form, Printed By: " + myUser
+ " On: " + System.DateTime.Now.ToShortDateString() + " At: " +
System.DateTime.Now.ToShortTimeString();
memoryImage = new Bitmap(s.Width, s.Height + 50, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.DrawString(strOne, mFont, Brushes.Black, 50, 25);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 50, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void pd_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e) {
e.Graphics.DrawImage(memoryImage, 15, 15);
}
private void cmPrintForm_Click(System.Object sender, System.EventArgs
e) {
if (this.Width > this.Height) {
pd.DefaultPageSettings.Landscape = true;
}
CaptureScreen();
//printDocument1.Print();
ppv.Width=1024;
ppv.Height=768;
ppv.ShowDialog();
}
Tomas said:
Hello All,
snip
1. The non-Visible part of a datagrid (not just the data in the
cells, but the lines, headers, etc.).
2. RTF (multiple font/color) text objects.
3. Mixed items text with pictures, etc.
4. Screenshots, etc.
Can anyone point to a good tutorial (online or paper) that covers
these types of things? Or at least covers the concepts?
Thanks,
-tomas