Hello,

I need to get an image from a control and all its children. I'm using
DrawToBitmap, but there are problems with the final result. There are
things that are not correctly painted on the image. I've tried other
approaches using the WM_PRINT message, but the result is the same.
Is there any way to get a perfect image? I can't use BitBlt or do a
screen capture because the control may be hidden from view.
Thanks in advance for any help given.

Regards,
paulo

Re: DrawToBitmap problem by Stoitcho

Stoitcho
Tue Mar 14 08:21:56 CST 2006

paulo,

What exactly is the problem with the final result?


--

Stoitcho Goutsev (100)

"paulo" <isf@nospam.nospam> wrote in message
news:uAXmdM2RGHA.4792@TK2MSFTNGP14.phx.gbl...
> Hello,
>
> I need to get an image from a control and all its children. I'm using
> DrawToBitmap, but there are problems with the final result. There are
> things that are not correctly painted on the image. I've tried other
> approaches using the WM_PRINT message, but the result is the same.
> Is there any way to get a perfect image? I can't use BitBlt or do a screen
> capture because the control may be hidden from view.
> Thanks in advance for any help given.
>
> Regards,
> paulo



Re: DrawToBitmap problem by paulo

paulo
Tue Mar 14 09:18:52 CST 2006

Hello Stoitcho,

Not every children control is painted correctly. There are labels
missing, and even some entire controls.
I read somewhere that not every control responds correctly to the
WM_PRINT message, which is used by DrawToBitmap.
Is there an alternative to get the control image?

Regards,
paulo

Stoitcho Goutsev (100) wrote:
> paulo,
>
> What exactly is the problem with the final result?
>
>

Re: DrawToBitmap problem by Stoitcho

Stoitcho
Tue Mar 14 10:13:47 CST 2006

That is true. Good example is the RichTextBox; it doesn't support WM_PRINT
I'm not sure there is workaround.

However I was trying to help a person in this ng sometime ago with similar
problem. He didn't mind using PInvoke and I suggested using PrintWindow API
instead of sending WM_PRINT. MSDN says it is similar of using WM_PRINT, but
actually it sends WM_PAINT isntead and works in some places where WM_PRINT
doesn't.

PrintWindows did't help the other guy, but might help you.

The following is reference to our conversation back then
http://groups.google.ca/group/microsoft.public.dotnet.framework.windowsforms/browse_frm/thread/846e6c395eefbcac/67806bd349b07f61?lnk=st&q=Goutsev+PrintWindow+group%3Amicrosoft.public.dotnet.*&rnum=1&hl=en#67806bd349b07f61


--
HTH
Stoitcho Goutsev (100)

"paulo" <isf@nospam.nospam> wrote in message
news:O8TJjq3RGHA.2300@TK2MSFTNGP11.phx.gbl...
> Hello Stoitcho,
>
> Not every children control is painted correctly. There are labels missing,
> and even some entire controls.
> I read somewhere that not every control responds correctly to the WM_PRINT
> message, which is used by DrawToBitmap.
> Is there an alternative to get the control image?
>
> Regards,
> paulo
>
> Stoitcho Goutsev (100) wrote:
>> paulo,
>>
>> What exactly is the problem with the final result?
>>


Re: DrawToBitmap problem by paulo

paulo
Tue Mar 14 13:33:44 CST 2006

Hello Stoitcho!

I want to thank you for your help.
PrintWindow is not perfect, but it sure is lots better than
DrawToBitmap. It works well 95% of the time!
Thank you so much for your help!

Regards,
paulo

Stoitcho Goutsev (100) wrote:
> That is true. Good example is the RichTextBox; it doesn't support WM_PRINT
> I'm not sure there is workaround.
>
> However I was trying to help a person in this ng sometime ago with similar
> problem. He didn't mind using PInvoke and I suggested using PrintWindow API
> instead of sending WM_PRINT. MSDN says it is similar of using WM_PRINT, but
> actually it sends WM_PAINT isntead and works in some places where WM_PRINT
> doesn't.
>
> PrintWindows did't help the other guy, but might help you.
>
> The following is reference to our conversation back then
> http://groups.google.ca/group/microsoft.public.dotnet.framework.windowsforms/browse_frm/thread/846e6c395eefbcac/67806bd349b07f61?lnk=st&q=Goutsev+PrintWindow+group%3Amicrosoft.public.dotnet.*&rnum=1&hl=en#67806bd349b07f61
>
>

Re: DrawToBitmap problem by jetan

jetan
Tue Mar 14 19:59:50 CST 2006

Hi paulo,

Thanks for your post!

Normally, a control is a Window, and it paint itself in WM_PAINT message,
if a control does not provide support for WM_PRINT message, it means that
it does not provide any interface to get the painting behavior. It just
does the painting internally and does not want outside world to get its
painting behavior.

Regarding this scenario, we may have 2 choices:
1. Using BitBlt method to copy the surface manually
2. ControlPaint class exposes some drawing methods, which can be used to
draw some standard controls.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.