G
Guest
I'm using Visual Studio 2005 and C#. I need to print a WinForm used for data
entry as a graphic. In other words, I need to print the exact WinForm the
user sees on the screen.
I searched through the newsgroups, and found the code below. This seems
reasonable, except for the fact that the author does not provide his
SetSeq_Library. This is needed to load the Bitmap variable _ActiveFormImage.
Any suggestions on how to capture a WinForm as a Bitmap to feed to a
PrintPageEventHandler?
I like this solution much better than using GDI+, which was required in
Visual Studio 2003.
Thanks,
--
Randy
protected void PrintActiveForm(object sender, EventArgs e)
{
ToolStripMenuItem MenuItem=(ToolStripMenuItem)sender;
//MessageBox.Show(MenuItem.Name);
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings();
PrintDocument PrtDoc = new PrintDocument();
_ActiveFormImage = SetSeg_Library.SetCapture.Form(this);
PrtDoc.PrintPage += new PrintPageEventHandler(PrtDoc_PrintPage);
PD.Document = PrtDoc;
PD.ShowDialog();
PrtDoc.Print();
}
void PrtDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(this._ActiveFormImage, 0, 0);
}
entry as a graphic. In other words, I need to print the exact WinForm the
user sees on the screen.
I searched through the newsgroups, and found the code below. This seems
reasonable, except for the fact that the author does not provide his
SetSeq_Library. This is needed to load the Bitmap variable _ActiveFormImage.
Any suggestions on how to capture a WinForm as a Bitmap to feed to a
PrintPageEventHandler?
I like this solution much better than using GDI+, which was required in
Visual Studio 2003.
Thanks,
--
Randy
protected void PrintActiveForm(object sender, EventArgs e)
{
ToolStripMenuItem MenuItem=(ToolStripMenuItem)sender;
//MessageBox.Show(MenuItem.Name);
PrintDialog PD = new PrintDialog();
PrinterSettings PS = new PrinterSettings();
PrintDocument PrtDoc = new PrintDocument();
_ActiveFormImage = SetSeg_Library.SetCapture.Form(this);
PrtDoc.PrintPage += new PrintPageEventHandler(PrtDoc_PrintPage);
PD.Document = PrtDoc;
PD.ShowDialog();
PrtDoc.Print();
}
void PrtDoc_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(this._ActiveFormImage, 0, 0);
}