Re: Printing an Form

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hey Gary,

Thanks for the code. As I said in my earlier reply I'm using VS2003 and I
guess I have to import that "gdi32.dll" but using your example I'm not sure
how to do that other than it requires "static extern". This is a little over
my head at this point.

Anyway I tried your code and I seem to be missing some key points. For one
I'm using the click event of a button so I don't think I need:
"ToolStripMenuItem MenuItem=(ToolStripMenuItem)sender;"
MessageBox.Show(MenuItem.Name);
Two, don't I need to call PrintActiveForm() and PrtDoc() ? And three, these
are some of the build errors I'm getting:

'TestDB.fclsPastInfo' does not contain a definition for '_ActiveFormImage'

'The name '_ActiveFormImage' does not exist in the class or namespace
'TestDB.fclsPastInfo'

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)

The type or namespace name 'PrtDoc' could not be found (are you missing a
using directive or an assembly reference?)
D.

"Gary Holbrook" wrote:

> 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
>
.


Quantcast