I've got a few tips to reduce or eliminate flickering:
- Turn on the Canvas.DoubleBuffer property.
- Turn off EraseBackground. EraseBackground causes the drawing area to be erased first, which will be flushed to the screen immediately causing flicker. This is important for both Canvas and ContainerControl classes. In ContainerControls, make sure the instance has it disabled, and if your code creates one of your ContainerControl subclass "out of thin air" then make sure your subclass has this disabled as well. Keep in mind that sometimes control artifacts can be left behind depending on the type of drawing you're doing, since they weren't erased first. My only suggestion is to try it and see how it works for your case.
- Only draw using the Canvas.Paint event. As much as we programmers like to say "Canvas, display this now" using the backdrop property, it is the wrong way to do it. Instead, when you want the canvas to forcefully update, use the refresh method. The backdrop property is only useful from the window editor, when you want to display a static / non-changing graphic.
- Whenever you call RectControl.Refresh, pass the optional EraseBackground parameter to it with a false value. This will prevent the control from erasing itself pre-refresh. See tip 2 above.
If you are already double buffering manually, there is no need for tip 1 in your case. In fact, you're better off leaving it disabled if you're going to do the buffering yourself. If your code looks similar to
Dim Buffer As New Picture(G.width,G.height,32)
// do your drawing to Buffer.Graphics
then you're buffering manually. If your paint event has more than a single call to the "G As Graphics" object, then you need to enable the DoubleBuffer property.
Buffering will prevent transparency however, so you might want to fill your area with a color first. This will also help prevent artifacts left over from disabling EraseBackground. Something like:
If Self.TrueWindow.HasBackColor Then
Buffer.Graphics.ForeColor = Self.TrueWindow.BackColor
Buffer.Graphics.ForeColor = FillColor
will work well to fill the buffer with the same color as the window it's placed on.
And there you go. Follow these tips, and the flickering effect on Windows will be greatly reduced.