Leadtools.Windows.Annotations Requires Document/Medical license. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AnnObjectCollection Class
See Also  Members   Example 
Leadtools.Windows.Annotations Namespace : AnnObjectCollection Class





Represents an ordered collection of AnnObjectBase.

Syntax

Visual Basic (Declaration) 
Public Class AnnObjectCollection 
   Inherits UIElementCollection
Visual Basic (Usage)Copy Code
Dim instance As AnnObjectCollection
C# 
public class AnnObjectCollection : UIElementCollection 
C++/CLI 
public ref class AnnObjectCollection : public UIElementCollection 
XAML Object Element Usage 

<AnnObjectCollection .../>

XAML Object Element Usage 

<AnnObjectCollection .../>

Example

Visual BasicCopy Code
Public Sub AnnObjectCollectionExample(ByVal container As AnnContainer)
   AddHandler container.Children.ObjectAdded, AddressOf container_ObjectAdded
   AddHandler container.Children.ObjectRemoved, AddressOf container_ObjectRemoved
   ' add a few objects
   Dim lineObj As AnnLineObject = New AnnLineObject()
   lineObj.X1 = 100
   lineObj.Y1 = 100
   lineObj.X2 = 200
   lineObj.Y2 = 200
   lineObj.Stroke = Brushes.Blue
   lineObj.StrokeThickness = 2.0
   lineObj.Header = "Object 1"

   Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
   rectObj.Left = 200
   rectObj.Top = 200
   rectObj.Width = 100
   rectObj.Height = 100
   rectObj.Stroke = Brushes.Blue
   rectObj.StrokeThickness = 2.0
   rectObj.Fill = Brushes.Transparent
   rectObj.Header = "Object 2"

   Dim ellipseObj As AnnEllipseObject = New AnnEllipseObject()
   ellipseObj.Left = 200
   ellipseObj.Top = 200
   ellipseObj.Width = 150
   ellipseObj.Height = 100
   ellipseObj.Stroke = Brushes.Yellow
   ellipseObj.StrokeThickness = 2.0
   Dim b As Brush = New SolidColorBrush(Colors.Green)
   b.Opacity = 0.5
   ellipseObj.Fill = b
   ellipseObj.Header = "Object 3"

   container.Children.Add(lineObj)
   container.Children.Add(rectObj)
   container.Children.Add(ellipseObj)

   ' insert new Object
   Dim newLineObj As AnnLineObject = CType(IIf(TypeOf lineObj.Clone() Is AnnLineObject, lineObj.Clone(), Nothing), AnnLineObject)
   newLineObj.X1 = 110
   newLineObj.Y1 = 110
   newLineObj.X2 = 210
   newLineObj.Y2 = 210
   newLineObj.Stroke = Brushes.Red
   newLineObj.StrokeThickness = 2.0
   newLineObj.Header = "New Object"

   container.Children.Insert(1, newLineObj)

   ' check if collection contains this new item
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj))

   ' remove this new item
   container.Children.Remove(newLineObj)
   System.Diagnostics.Debug.Assert((Not container.Children.Contains(newLineObj)))

   ' remove the last item
   container.Children.RemoveAt(container.Children.Count - 1)
   System.Diagnostics.Debug.Assert(container.Children.Count = 2)

   ' send the first item to the end of the collection
   container.Children.SendToBack(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = container.Children.Count - 1)

   ' bring it back to the front
   container.Children.BringToFront(lineObj, True)
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) = 0)

   ' clean the collection
   container.Children.Clear()
   System.Diagnostics.Debug.Assert(container.Children.Count = 0)
End Sub

Private Sub container_ObjectAdded(ByVal sender As Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been added to the collection")
End Sub

Private Sub container_ObjectRemoved(ByVal sender As System.Object, ByVal e As AnnObjectCollectionEventArgs)
   Console.WriteLine("The Object ((" & e.Object.Header & ")) Has been removed from the collection")
End Sub
C#Copy Code
public void AnnObjectCollectionExample(AnnContainer container) 

   container.Children.ObjectAdded += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectAdded); 
   container.Children.ObjectRemoved += new EventHandler<AnnObjectCollectionEventArgs>(container_ObjectRemoved); 
   // add a few objects 
   AnnLineObject lineObj = new AnnLineObject(); 
   lineObj.X1 = 100; 
   lineObj.Y1 = 100; 
   lineObj.X2 = 200; 
   lineObj.Y2 = 200; 
   lineObj.Stroke = Brushes.Blue; 
   lineObj.StrokeThickness = 2.0; 
   lineObj.Header = "Object 1"; 
 
   AnnRectangleObject rectObj = new AnnRectangleObject(); 
   rectObj.Left = 200; 
   rectObj.Top = 200; 
   rectObj.Width = 100; 
   rectObj.Height = 100; 
   rectObj.Stroke = Brushes.Blue; 
   rectObj.StrokeThickness = 2.0; 
   rectObj.Fill = Brushes.Transparent; 
   rectObj.Header = "Object 2"; 
 
   AnnEllipseObject ellipseObj = new AnnEllipseObject(); 
   ellipseObj.Left = 200; 
   ellipseObj.Top = 200; 
   ellipseObj.Width = 150; 
   ellipseObj.Height = 100; 
   ellipseObj.Stroke = Brushes.Yellow; 
   ellipseObj.StrokeThickness = 2.0; 
   Brush b = new SolidColorBrush(Colors.Green); 
   b.Opacity = 0.5; 
   ellipseObj.Fill = b; 
   ellipseObj.Header = "Object 3"; 
 
   container.Children.Add(lineObj); 
   container.Children.Add(rectObj); 
   container.Children.Add(ellipseObj); 
 
   // insert new Object 
   AnnLineObject newLineObj = lineObj.Clone() as AnnLineObject; 
   newLineObj.X1 = 110; 
   newLineObj.Y1 = 110; 
   newLineObj.X2 = 210; 
   newLineObj.Y2 = 210; 
   newLineObj.Stroke = Brushes.Red; 
   newLineObj.StrokeThickness = 2.0; 
   newLineObj.Header = "New Object"; 
 
   container.Children.Insert(1, newLineObj); 
 
   // check if collection contains this new item  
   System.Diagnostics.Debug.Assert(container.Children.Contains(newLineObj)); 
 
   // remove this new item  
   container.Children.Remove(newLineObj); 
   System.Diagnostics.Debug.Assert(!container.Children.Contains(newLineObj)); 
 
   // remove the last item  
   container.Children.RemoveAt(container.Children.Count - 1); 
   System.Diagnostics.Debug.Assert(container.Children.Count == 2); 
 
   // send the first item to the end of the collection  
   container.Children.SendToBack(lineObj, true); 
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == container.Children.Count - 1); 
 
   // bring it back to the front  
   container.Children.BringToFront(lineObj, true); 
   System.Diagnostics.Debug.Assert(container.Children.IndexOf(lineObj) == 0); 
 
   // clean the collection  
   container.Children.Clear(); 
   System.Diagnostics.Debug.Assert(container.Children.Count == 0); 

 
private void container_ObjectAdded(object sender, AnnObjectCollectionEventArgs e) 

   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been added to the collection"); 

 
private void container_ObjectRemoved(System.Object sender, AnnObjectCollectionEventArgs e) 

   Console.WriteLine("The Object ((" + e.Object.Header + ")) Has been removed from the collection"); 
}

Inheritance Hierarchy

System.Object
   System.Windows.Controls.UIElementCollection
      Leadtools.Windows.Annotations.AnnObjectCollection

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also

AnnObjectCollection requires a Document/Medical product license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features and Unlocking Special LEAD Features.