tomko wrote:
I've found a way to copy the visible presentation of a control on to a
picturebox (using Graphics and GDI). But this works only if the
control is visible. How can I have the control hidden and still
retreive the graphics of the control (have the control draw itself for
me)? And what makes a child control hide itself when its parent is
hidden?
It probably depends on the control.
For a control that is entirely managed code, the first thing I'd try is
the DrawToBitmap() method. But it's possible that if you really want to
do this, you might have to subclass the control, create your own Bitmap
for it to draw into, get a Graphics instance from the Bitmap, and then
call OnPaint with a PaintEventArgs with the Graphics property set to
your Graphics instance.
For a control that is substantially unmanaged code (ie, pretty much any
of the built-in controls), it's likely a lot more difficult or
impossible. If it's possible at all, you probably will have to use the
WM_PRINTCLIENT window message, sending it directly to the underlying
window handle for the control. You need to create the Bitmap and
Graphics as above, but then get the HDC from the Graphics and use that
as the wParam when sending the WM_PRINTCLIENT message.
This of course requires that the control actually handles the
WM_PRINTCLIENT message. According to MSDN all of the common controls
do, but you could run into exceptions anyway.
Trying to hack the normal to-screen drawing process of a control,
especially for controls that are essentially unmanaged, is likely to get
you nothing but headaches. :) Hopefully the above ideas give you
something more likely to work regardless of the on-screen state of the
control.
Pete