This document is archived and information here might be outdated.  Recommended version.


Invalidating the display (ArcObjects .NET 10.5 SDK)

Invalidating the display


About invalidating the display

When making changes to an existing feature, or when creating a feature, one of the important tasks a developer is responsible for is updating the display to reflect those changes. This is particularly important when editing in order to provide visual feedback to the user about the result of their edit.
Edits often are against just one or a few features in the current display extent. In these cases, it is inefficient to refresh the entire display, which can result in reduced application performance.
When creating a feature, only the envelope and symbology of the new feature's location are required to refresh the minimum display extent. The following code example shows how to invalidate the display when creating a new feature. Acquire a reference to IFeatureRenderer via the editor's CurrentTemplate. From here, you can access the associated target layer. In most cases, the IScreenDisplay object being passed in is the editor's display (IEditor.Display).
[C#]
public void InvalidateDisplay(IScreenDisplay display, IFeature feature,
    IFeatureRenderer featRenderer)
{
    if (display == null || feature == null || featRenderer == null)
        return ;
    //Invalidate the envelope of the newly created feature.
    ISymbol featureSym=featRenderer.get_SymbolByFeature(feature);
    //Create an InvalidArea object and assign input parameters.
    IInvalidArea3 invArea=new InvalidAreaClass();
    invArea.Display=display;
    invArea.AddFeature(feature, featureSym);
    invArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
}
[VB.NET]
Public Sub InvalidateDisplay(ByVal display As IScreenDisplay, ByVal feature As IFeature, ByVal featRenderer As IFeatureRenderer)
    If display Is Nothing OrElse feature Is Nothing OrElse featRenderer Is Nothing Then
        Exit Sub
    End If
    
    'Invalidate the envelope of the newly created feature.
    Dim featureSym As ISymbol=featRenderer.get_SymbolByFeature(feature)
    
    'Create an InvalidArea object and assign input parameters.
    Dim invArea As IInvalidArea3=New InvalidAreaClass()
    invArea.Display=display
    invArea.AddFeature(feature, featureSym)
    invArea.Invalidate(CShort(esriScreenCache.esriAllScreenCaches))
End Sub
If you're creating multiple features in a single edit operation, command, or tool, add all new features to the InvalidArea object before calling IInvalidArea.Invalidate.
When updating the position of existing features, you must include the old and new feature locations to invalidate the display properly. If the editor's selection (EditSelection) is the set of features being operated on, you can pass this in directly since IInvalidArea.Add supports IEnumFeature as input. This does not, however, take the symbol into account when invalidating the display.


See Also:

How to redraw the display




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic