I wish to off-screen render a Control to some bitmap so that I have quick access to it.
Unfortunately Control.DrawToBitmap
seems to draw the entire control on which it is called including all it's child controls. Internally it issues a WM_PRINT message with self-provided DC to a bitmap. This temporary bitmap is then blitted to the user-provided Bitmap. Unacceptable for me, I'd rather have this bitmap updated as needed so my performance hit when the bitmap is needed is minimized.
In the ideal scenario I'd want the form to behave as if it were visible on the screen (but it cannot be). That would mean that if, say, some Control has its Text
property changed, the form would be partially invalidated. Catching the relevant messages/events would then allow me to either specify my own DC for the form to be drawn on, or to simply BitBlt the forms DC to my own.
Some directions I have looked in:
- The
PaintEventArgs
parameter inOnPaint
seems to hold a member savedGraphicsState, perhaps it could be used to figure out what doesn't require invalidating - Having the form visible but outside the screen area. Controls then don't get painted, though.
- Manually calling RedrawWindow() on the window, same story
DrawToBitmap
(theWM_PRINT
message) is unacceptable for your use. Are you worried about performance? It's very unlikely that drawing into a bitmap is going to be any slower than drawing onto the screen. – Rebekah