I have a group of labels and some shapes that are being animated (updated once very 20 ms or so). To reduce the flicker, I thought I would put them in a picturebox, and then just bitblt from the box to the form instead of showing the box.
The problem I'm noticing now is this:
If you bitblt from the box when it is not visible (or offscreen), it seems that only the background (and none of the controls) will appear on the form (after blting).
The only way I can seem to get the controls to show up when I blt from the box is to have the box visible (which defeats the purpose of using it as a buffer).
Is it possible to blt from an invisible picturebox and have the controls in the picturebox show up (not just the background)?
I don't know if that is possible, hopefully somebody who knows will chime in.
What I do know is that the "proper" way of drawing items yourself (using the .Print/.Line/.Circle/etc methods) rather than using controls will not have that problem, and will also not have flicker. Unfortunately it is likely to require a little more work.
Yeah I've done buffering before, but I guess this time I was trying to be lazy because it was a fairly small project. I guess thats what I get for going cheap. I can replace the graphics by drawing them in, but what about the text?
Is there a way to use Print (or something else) so I don't have to resort to API text? The only time I've ever used print it always just prints at 0,0 first and then goes down line by line. I would need to position the text.
As mentioned already, drawing them yourself may be optimal.
But here is a way to BitBlt (sort of) from a non-visible picturebox with following restrictions
1. The entire picturebox area is painted, can't just do part of it
2. SendMessage vs BitBlt
Code:
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Const WM_PAINT As Long = &HF&
Private Sub Command1_Click()
SendMessage Picture1.hwnd, WM_PAINT, Picture2.hDC, ByVal 0&
End Sub
Insomnia is just a byproduct of, "It can't be done"
Is it possible to blt from an invisible picturebox and have the controls in the picturebox show up (not just the background)?
When the container (your PictureBox in this case) is hidden, its contents (Labels and Shape, etc in this case) are hidden.
It has all the merits to draw by yourself texts and shapes including lines. More flexible and simpler in coding, and better quality in results -- the appended images shall illustrate some of the points.
Once drawn, you can BitBlt or StretchBlt even if the PictureBox is made invisible.
Last edited by petersen; Oct 20th, 2010 at 12:43 PM.