Back to Devexpress

ChartControl.AnnotationRepositoryChanging Event

windowsforms-devexpress-dot-xtracharts-dot-chartcontrol-d1641f49.md

latest6.8 KB
Original Source

ChartControl.AnnotationRepositoryChanging Event

Occurs when a user adds, edits or deletes an annotation before the user’s operation is applied to the annotation repository.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.UI.dll

NuGet Package : DevExpress.Win.Charts

Declaration

csharp
public event AnnotationRepositoryChangingEventHandler AnnotationRepositoryChanging
vb
Public Event AnnotationRepositoryChanging As AnnotationRepositoryChangingEventHandler

Event Data

The AnnotationRepositoryChanging event's data class is AnnotationRepositoryChangingEventArgs. The following properties provide information specific to this event:

PropertyDescription
AnnotationReturns the annotation that is being changed.
CancelIndicates whether to cancel the annotation change.
ChangeReturns the AnnotationRepositoryChange value that indicates the type of change a user makes.

Remarks

Users can utilize the Add Text Annotation and Add Image Annotation buttons in the Chart’s Ribbon or Toolbars to add interactive annotations. They can also edit or delete an annotation if the Annotation.RuntimeEditing property is set to true.

The e.Change property returns an operation that a user performs. The Change property can be set to the following values:

The e.Annotation property returns the changed annotation. The e.Cancel property indicates whether to cancel the last change.

The following example prevents Annotation1 from being deleted.

csharp
void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Annotation.Name == "Annotation1" && e.Change == AnnotationRepositoryChange.Deletion) {
        e.Cancel = true;
    }
}
vb
Private Sub chartControl1_AnnotationRepositoryChanging(ByVal sender As Object, ByVal e As AnnotationRepositoryChangingEventArgs)
    If e.Annotation.Name = "Annotation 1" AndAlso e.Change = AnnotationRepositoryChange.Deletion Then
        e.Cancel = True
    End If
End Sub

When a user edits an image annotation, use AnnotationImageEditingEventArgs to get a file path to the new annotation image. Cast AnnotationRepositoryChangingEventArgs to the AnnotationImageEditingEventArgs type and use the AnnotationImageEditingEventArgs.NewImageFileName property for this purpose:

csharp
void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Change == AnnotationRepositoryChange.Image) {
    AnnotationImageEditingEventArgs imageEditingArgs = (AnnotationImageEditingEventArgs)e;
    string imageFile = imageEditingArgs.NewImageFileName;
    //Add your logic here. 
    }
 }
vb
Private Sub chartControl1_AnnotationRepositoryChanging(ByVal sender As Object, ByVal e As AnnotationRepositoryChangingEventArgs)
    If e.Change = AnnotationRepositoryChange.Image Then
        Dim imageEditingArgs As AnnotationImageEditingEventArgs = CType(e, AnnotationImageEditingEventArgs)
        Dim imageFile As String = imageEditingArgs.NewImageFileName
    End If
'Add your logic here.     
End Sub

When a user edits a text annotation, use the AnnotationTextEditingEventArgs to get new annotation text. Cast the AnnotationRepositoryChangingEventArgs to the AnnotationTextEditingEventArgs type. The AnnotationTextEditingEventArgs.NewText property returns new text as shown in the following example:

csharp
void chartControl1_AnnotationRepositoryChanging(object sender, AnnotationRepositoryChangingEventArgs e) {
    if (e.Change == AnnotationRepositoryChange.Text) {
    AnnotationTextEditingEventArgs textEditingArgs = (AnnotationTextEditingEventArgs)e;
    string newAnnotationText = textEditingArgs.NewText;
    //Add your logic here. 
    }    
}
vb
Private Sub chartControl1_AnnotationRepositoryChanging(ByVal sender As Object, ByVal e As AnnotationRepositoryChangingEventArgs)
    If e.Change = AnnotationRepositoryChange.Text Then
        Dim textEditingArgs As AnnotationTextEditingEventArgs = CType(e, AnnotationTextEditingEventArgs)
        Dim newAnnotationText As String = textEditingArgs.NewText
        'Add your logic here.
    End If
End Sub

See Also

AnnotationRepositoryChanged

ChartControl Class

ChartControl Members

DevExpress.XtraCharts Namespace