Different combinations of AutoRedraw and ClipControls have different effects on the way graphical controls and graphics methods paint to the screen.
As you create graphics, keep in mind that graphical controls and labels, nongraphical controls, and graphics methods appear on different layers in a container. The behavior of these layers depends on three factors:
Usually, the layers of a form or other container are, from front to back, as follows:
Layer | Contents |
Front | Nongraphical controls like command buttons, check boxes, and file controls. |
Middle | Graphical controls and labels. |
Back | Drawing space for the form or container. This is where the results of graphics methods appear. |
Anything in one layer covers anything in the layer behind, so graphics you create with the graphical controls appear behind the other controls on the form, and all graphics you create with the graphics methods appear below all graphical and nongraphical controls. The normal arrangement of layers is shown in Figure 12.9.
Figure 12.9 Normal layering of graphics on a form
You can produce normal layering using any of several approaches. Combining settings for AutoRedraw and ClipControls and placing graphics methods inside or outside the Paint event affects layering and the performance of the application.
The following table lists the effects created by different combinations of AutoRedraw and ClipControls and placement of graphics methods.
AutoRedraw |
ClipControls |
Graphics methods in/out of Paint event | Layering behavior |
True | True (default) |
Paint event ignored |
Normal layering. |
True | False | Paint event ignored |
Normal layering. Forms with many controls that do not overlap may paint faster because no clipping region is calculated or created. |
False (default) |
True (default) |
In | Normal layering. |
False | True | Out | Nongraphical controls in front. Graphics methods and graphical controls appear mixed in the middle and back layers. Not recommended. |
False | False | In | Normal layering, affecting only pixels that were previously covered or that appear when resizing a form. |
False | False | Out | Graphics methods and all controls appear mixed in the three layers. Not recommended. |
Setting AutoRedraw to True always produces normal layering. While using AutoRedraw is the easiest way to layer graphics, applications with large forms may suffer from reduced performance due to the memory demands of AutoRedraw.
When AutoRedraw is True, the setting of ClipControls has no effect on how graphics layer on a form or in a container. But ClipControls can affect how fast the form displays. When ClipControls is False, the application doesn’t create a clipping region. Not having to calculate or paint to avoid holes in a clipping region may cause the form to display faster.
Also, when AutoRedraw and ClipControls are both False, the application repaints only the pixels of a form or container that are exposed by:
When AutoRedraw is False, the best place to use graphics methods is within the Paint event of the form or container. Confining graphics methods to the Paint event causes those methods to paint in a predictable sequence.
Using graphics methods outside a Paint event when AutoRedraw is False can produce unstable graphics. Each time the output of a graphics method appears on the form or container, it may cover any controls or graphics methods already there (if ClipControls is False). When an application uses more than a few graphics methods to create visual effects, managing the resulting output can be extremely difficult unless the methods are all confined to the Paint event.