-
Metafiles
I have a PictureBox that contains an Image control.
That Image control contains a WMF (Windows MetaFile).
The PictureBox also contains some Label Controls which I want to move around PictureBox.
When using the Move method, the moving Label control does flicker a lot. When setting the Image control's picture to nothing (or when setting it invisible), the flicker no longer occurs!
The flicker frequency also depends on the complexity of the WMF.
Help? I do not want the flicker!
-
The only thing I can come up with is to draw the text contained in label(s) using the TextOut API.
-
There is an article on VBWorld that uses an API to remove flicker. The reason that you are getting the flickers is that everytime the label moves, the WMF redraws itself (WMF files are simply a series of steps that uses API calls to draw, like LineTo, Rectangle, etc. It is not a collection of pixels). After the WMF redraws, your label redraws. This causes flicker. Use the LockWindowUpdate() API call before you call Move:
Code:
LockWindowUpdate(pic1.hwnd)
Label1.Move(...)
LockWindowUpdate(0)
That should work.
Z.
-
The LockWindowUpdat() API won't do it, because moving lables across its 'locked' parent won't update the screen!
Only when LockWindowUpdate(0&) is given, the screen will be updated.
But, now I found the solution: I made the Image Control invisible, loaded a WMF into it and used the PlayMetaFile() API directly to the Image Control's parent (=PictureBox).
Now it works smoothly without the flicker!
I had to do this workaround because in VB3, the PlayMetaFile() API doesn't recognize Aldus Placeable Metafiles...
-
If you do it correctly, LockWindowUpdate() will do the trick. It will draw everything, then when you unlock, its almost like BitBlt from a back buffer.
Z.
-
Not quite sure...
But would the lockwindowupdate also get rid of the speed drop when it's redrawing? Although you can't see it doesn't mean it doesn't get drawn, right? (theoretically)
And another problem: if any other window moves over the locked window, and LockWindowUpdate(0) is called, the whole desktop repaints :(
-
1 Attachment(s)
Ho, guys, I know that my solution (using PlayMetaFile) is good.
But as a reaction to the LockWindowUpdate API, I wrote some code to demonstrate this behaviour - see the attachment.
Try moving the label without the checkbox clicked and then with the checkbox clicked. See the difference and say that I was right, not?
-
No VB here, but looking at your code, you only call LockWindowUpdate() once, I think what we meant was, call LockWindowUpdate before moving, then call again with 0& afterwards, and do this everytime you move :)
-
This will implement continously a Refresh, which will encourage the flicker, not?
-
It refreshes only after everything has been drawn, thus reducing flicker theoretically. But it's better to have a backbuffer instead of using LockWindowUpdate, like I said, LockWindowUpdate could cause the whole desktop to be repainted, which causes even more flicker than without it :)
-
I do not use LockWindowUpdate() anymore because the whole desktop refreshes.
Alternatively, I use the WM_SETREDRAW message to the hWnd. This locks only the given window and after the lock everything is drawn very smoothly.
I use this message for simulating a multi-color ListBox using a PictureBox instead.
For smooth redrawing:
SendMessage (hWnd, WM_SETREDRAW, 0&, 0&) 'LOCK
'... do the redrawing in the hWnd
SendMessage (hWnd, WM_SETREDRAW, 1&, 0&) 'UNLOCK
'don't forget to use the Refresh method of the object