Как отфильтровать аннотации при загрузке?
В этом разделе
Вот C#/VB.NET код, который демонстрирует, как отфильтровать аннотации при загрузке коллекции аннотаций:
/// <summary>
/// Adds filtering of annotations when annotation collection is loaded.
/// </summary>
public static void AddAnnotationsLoadFilter(Vintasoft.Imaging.Annotation.UI.AnnotationViewer viewer)
{
// Subscribe to the AnnotationsDataChanged event of viewer.
SubscribeToViewerEvents(viewer);
// Subscribe to the CollectionAdded event of annotation data controller.
SubscribeToControllerEvents(viewer.AnnotationDataController);
}
/// <summary>
/// Subscribe to the AnnotationsDataChanged event of viewer.
/// </summary>
private static void SubscribeToViewerEvents(Vintasoft.Imaging.Annotation.UI.AnnotationViewer viewer)
{
viewer.AnnotationDataControllerChanged +=
new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerChangedEventArgs>(viewer_AnnotationsDataChanged);
}
/// <summary>
/// Handler of the AnnotationsDataChanged event.
/// </summary>
private static void viewer_AnnotationsDataChanged(object sender,
Vintasoft.Imaging.PropertyChangedEventArgs<Vintasoft.Imaging.Annotation.AnnotationDataController> e)
{
// Unsubscribe from the events of previous annotation data controller.
UnsubscribeFromControllerEvents(e.OldValue);
// Subscribe to the events of new annotation data controller.
SubscribeToControllerEvents(e.NewValue);
}
/// <summary>
/// Subscribe to the CollectionAdded event of annotation data controller.
/// </summary>
private static void SubscribeToControllerEvents(Vintasoft.Imaging.Annotation.AnnotationDataController dataController)
{
dataController.CollectionAdded +=
new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs>(dataController_CollectionAdded);
}
/// <summary>
/// Unsubscribe from the CollectionAdded event of annotation data controller.
/// </summary>
private static void UnsubscribeFromControllerEvents(Vintasoft.Imaging.Annotation.AnnotationDataController dataController)
{
if (dataController != null)
dataController.CollectionAdded -=
new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs>(dataController_CollectionAdded);
}
/// <summary>
/// Handler of the CollectionAdded event.
/// </summary>
private static void dataController_CollectionAdded(object sender,
Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs e)
{
// Annotation data collection is added to the annotation data controller,
// at this moment we can filter annotations.
// Filter the annotations.
ApplyAnnotationFilter(e.AnnotationDataCollection);
}
/// <summary>
/// Filters the annotations of annotation data collection.
/// </summary>
private static void ApplyAnnotationFilter(Vintasoft.Imaging.Annotation.AnnotationDataCollection dataCollection)
{
// For each annotation in collection.
foreach (Vintasoft.Imaging.Annotation.AnnotationData data in dataCollection)
{
// If annotation is stamp.
if (data is Vintasoft.Imaging.Annotation.StampAnnotationData)
// Make annotation invisible.
data.IsVisible = false;
}
}
''' <summary>
''' Adds filtering of annotations when annotation collection is loaded.
''' </summary>
Public Shared Sub AddAnnotationsLoadFilter(viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer)
' Subscribe to the AnnotationsDataChanged event of viewer.
SubscribeToViewerEvents(viewer)
' Subscribe to the CollectionAdded event of annotation data controller.
SubscribeToControllerEvents(viewer.AnnotationDataController)
End Sub
''' <summary>
''' Subscribe to the AnnotationsDataChanged event of viewer.
''' </summary>
Private Shared Sub SubscribeToViewerEvents(viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer)
AddHandler viewer.AnnotationDataControllerChanged, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerChangedEventArgs)(AddressOf viewer_AnnotationsDataChanged)
End Sub
''' <summary>
''' Handler of the AnnotationsDataChanged event.
''' </summary>
Private Shared Sub viewer_AnnotationsDataChanged(sender As Object, e As Vintasoft.Imaging.PropertyChangedEventArgs(Of Vintasoft.Imaging.Annotation.AnnotationDataController))
' Unsubscribe from the events of previous annotation data controller.
UnsubscribeFromControllerEvents(e.OldValue)
' Subscribe to the events of new annotation data controller.
SubscribeToControllerEvents(e.NewValue)
End Sub
''' <summary>
''' Subscribe to the CollectionAdded event of annotation data controller.
''' </summary>
Private Shared Sub SubscribeToControllerEvents(dataController As Vintasoft.Imaging.Annotation.AnnotationDataController)
AddHandler dataController.CollectionAdded, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)(AddressOf dataController_CollectionAdded)
End Sub
''' <summary>
''' Unsubscribe from the CollectionAdded event of annotation data controller.
''' </summary>
Private Shared Sub UnsubscribeFromControllerEvents(dataController As Vintasoft.Imaging.Annotation.AnnotationDataController)
If dataController IsNot Nothing Then
RemoveHandler dataController.CollectionAdded, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)(AddressOf dataController_CollectionAdded)
End If
End Sub
''' <summary>
''' Handler of the CollectionAdded event.
''' </summary>
Private Shared Sub dataController_CollectionAdded(sender As Object, e As Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)
' Annotation data collection is added to the annotation data controller,
' at this moment we can filter annotations.
' Filter the annotations.
ApplyAnnotationFilter(e.AnnotationDataCollection)
End Sub
''' <summary>
''' Filters the annotations of annotation data collection.
''' </summary>
Private Shared Sub ApplyAnnotationFilter(dataCollection As Vintasoft.Imaging.Annotation.AnnotationDataCollection)
' For each annotation in collection.
For Each data As Vintasoft.Imaging.Annotation.AnnotationData In dataCollection
' If annotation is stamp.
If TypeOf data Is Vintasoft.Imaging.Annotation.StampAnnotationData Then
' Make annotation invisible.
data.IsVisible = False
End If
Next
End Sub