469,610 Members | 2,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Printing the Active MDI Child

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
Nov 16 '05 #1
5 5183
Check this link

http://msdn.microsoft.com/library/de...us/cscon/html/
vclrfcodeprintpreviewingformvisualc.asp

--
Shak
(Houston)
"Randy" <rb***@sumaria.net> wrote in message
news:Bc******************@nwrdny02.gnilink.net...
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

Nov 16 '05 #2
Printing form

http://msdn.microsoft.com/library/de...us/cscon/html/
vclrfcodeprintpreviewingformvisualc.asp

--
Shak
(Houston)
"Randy" <rb***@sumaria.net> wrote in message
news:Bc******************@nwrdny02.gnilink.net...
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

Nov 16 '05 #3
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);

}


"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Printing form

http://msdn.microsoft.com/library/de...us/cscon/html/ vclrfcodeprintpreviewingformvisualc.asp

--
Shak
(Houston)
"Randy" <rb***@sumaria.net> wrote in message
news:Bc******************@nwrdny02.gnilink.net...
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


Nov 16 '05 #4

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.

--
Shak
(Houston)


"Randy" <rb***@sumaria.net> wrote in message
news:no******************@nwrdny01.gnilink.net...
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);

}


"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Printing form

http://msdn.microsoft.com/library/de...us/cscon/html/
vclrfcodeprintpreviewingformvisualc.asp

--
Shak
(Houston)
"Randy" <rb***@sumaria.net> wrote in message
news:Bc******************@nwrdny02.gnilink.net...
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



Nov 16 '05 #5
Thanks.

Randy

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl...

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.

--
Shak
(Houston)


"Randy" <rb***@sumaria.net> wrote in message
news:no******************@nwrdny01.gnilink.net...
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);

}


"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
Printing form

http://msdn.microsoft.com/library/de...us/cscon/html/
vclrfcodeprintpreviewingformvisualc.asp

--
Shak
(Houston)
"Randy" <rb***@sumaria.net> wrote in message
news:Bc******************@nwrdny02.gnilink.net...
> 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
>
>



Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Svennglenn | last post: by
1 post views Thread by alb120 | last post: by
3 posts views Thread by Chrisitiaan | last post: by
reply views Thread by Morten Wennevik | last post: by
reply views Thread by Frank_00001 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.