Printing the Active MDI Child

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

In my MDI parent, I can do the following:

Form childForm = (Form)this.ActiveMdiChild;

I'd like to send the childForm in it's current state to the printer. Current
state being whatever text is currently in the textboxes on the form also
prints.

Thanks,

Randy
 
Thanks for the response. I tried plugging that in as is, and the print
preview dialog comes up with "The document does not contain any pages." I
thought, "of course," and modified CaptureScreen() to use the
ActiveMdiChild, rather than "this". Still get "The document does not contain
any pages." Any thoughts? Again, I'm working in an Mdi parent, trying to
print the current mdi child form.

Randy



private void CaptureScreen()

{

Form form = (Form)this.ActiveMdiChild;

Console.WriteLine("Form name: {0}", form.Name);

Graphics mygraphics = form.CreateGraphics();

Size s = form.Size;

memoryImage = new Bitmap(s.Width, s.Height, mygraphics);

Graphics memoryGraphics = Graphics.FromImage(memoryImage);

IntPtr dc1 = mygraphics.GetHdc();

IntPtr dc2 = memoryGraphics.GetHdc();

BitBlt(dc2, 0, 0, form.ClientRectangle.Width, form.ClientRectangle.Height,
dc1, 0, 0, 13369376);

mygraphics.ReleaseHdc(dc1);

memoryGraphics.ReleaseHdc(dc2);

}
 
Randy,

Try this,

Form pChildform = (Form)this.ActiveMdiChild;

if(pChildForm != null)
{
//access a method which will do the printing
pChildForm.DoPrintForm();
}

Keep a method called DoPrintForm inside the ChildForm and place ALL the
printing related code there as described by MSDN.

It shld print properly.

Shak.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top