I can give you some generic information. It depends on what version of
VS you're using. You need to "take a picture" of the form, and pass
that to the drawing object when you print. With VS 2005, there is
actually a copy function you can use. With older versions you may need
to import GDI32 and make calls to that.
This is the code I use to print a form:
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);
}
CsharpNewcommer wrote:
Hi
I have designed a form containing data and I want to print that form and the
data as it appears in the Windows Form. I am a beginner with C# and I have
read several "help"s on PrintPage, PrintDialog, etc. but none seem to address
the issue of printing directly from the form. They all talk about printing
from a text file.
Can someone tell me how to print the form and maybe direct me on which to
use PrintPage, PrintDialog....which?
Thanks
D