How to redraw the display


Summary
This topic explains the use of Refresh versus Invalidate to redraw the display.


Available methods

When redrawing the display, any of the following methods can be called by the client:
Typically, however, you won't call Invalidate directly. If you're using a view in your application—for example, Map or PageLayout—the view itself can be used to refresh the screen. The view manages the display's caches and identifies the best way to carry out invalidation.

PartialRefresh

The PartialRefresh method of IActiveView lets you specify the part of the view to redraw and allows the view to work with display caches in a way that makes drawing quick and efficient. PartialRefresh uses the information it has of the cache layout to invalidate as little as possible. Ensure PartialRefresh is called using the most specific arguments possible to optimize drawing. The PartialRefresh method is the recommended method for redrawing and should be used whenever possible.
The following table shows the arguments for PartialRefresh and their effect on the view (Map or PageLayout) in which they are called:
Draw phase
Map
PageLayout
esriViewBackground
Unused
Page/snap grid
esriViewGeography
Layers
Unused
esriViewGeoSelection
Feature selection
Unused
esriViewGraphics
Labels/graphics
Graphics
esriViewGraphicSelection
Graphic selection
Element selection
esriViewForeground
Unused
Map guides

Refresh

The Refresh method of IActiveView draws everything, which is very inefficient. Only call Refresh when absolutely necessary, since this is usually a time-consuming operation. Use PartialRefresh instead if possible.

Invalidate

The Invalidate method of IScreenDisplay allows the refresh of specific regions on display. This approach is not recommended for clients because it requires manual control of drawing caches and invalidation and may not be optimized by the client for drawing. Use PartialRefresh instead if possible.

Redrawing the display

To redraw specific draw phases with calls to the PartialRefresh method, perform the following steps:
Note the use of optional arguments.
  1. Refresh a single layer as shown in the following code:
[VB.NET]
pMap.PartialRefresh(esriViewGeography, pLayer, Nothing)
[C#]
pMap.PartialRefresh(esriViewGeography, pLayer, null);
  1. Refresh all layers as shown in the following code:
[VB.NET]
pMap.PartialRefresh(esriViewGeography, Nothing, Nothing)
[C#]
pMap.PartialRefresh(esriViewGeography, null, null);
  1. Refresh the feature selection as shown in the following code:
When selecting features, you must call PartialRefresh twice, once before and once after the feature selection operation.
[VB.NET]
pMap.PartialRefresh(esriViewGeoSelection, Nothing, Nothing)
[C#]
pMap.PartialRefresh(esriViewGeoSelection, null, null);
  1. Refresh the labels as shown in the following code:
[VB.NET]
pMap.PartialRefresh(esriViewGraphics, Nothing, Nothing)
[C#]
pMap.PartialRefresh(esriViewGraphics, null, null);
  1. Refresh a single graphic element as shown in the following code:
[VB.NET]
pLayout.PartialRefresh(esriViewGraphics, pElement, Nothing)
[C#]
pLayout.PartialRefresh(esriViewGraphics, pElement, null);
  1. Refresh all graphic elements as shown in the following code:
[VB.NET]
pLayout.PartialRefresh(esriViewGraphics, Nothing, Nothing)
[C#]
pLayout.PartialRefresh(esriViewGraphics, null, null);
  1. Refresh the graphic selection as shown in the following code:
[VB.NET]
pLayout.PartialRefresh(esriViewGraphicSelection, Nothing, Nothing)
[C#]
pLayout.PartialRefresh(esriViewGraphicSelection, null, null);
Invalidating any phase causes the recording cache to be invalidated also. To force a redraw from the recording cache, use the call in the following code example:
[VB.NET]
pScreenDisplay.Invalidate(Nothing, False, esriNoScreenCache)
[C#]
pScreenDisplay.Invalidate(null, FALSE, esriNoScreenCache);


See Also:

How to add display caching
Display Library Overview




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine