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



Represents an Annotation container.

Object Model




Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class AnnContainer 
Visual Basic (Usage)Copy Code
Dim instance As AnnContainer
C# 
[SerializableAttribute()]
public class AnnContainer 
C++/CLI 
[SerializableAttribute()]
public ref class AnnContainer 

Example

This example creates a new AnnContainer object, links it to a RasterImageViewer object, adds a few objects and then draws the container on top of the viewer. Moving the mouse over an object displays the object type in the title bar.

Visual BasicCopy Code
Private Class MyForm1 : Inherits Form
   Private myAnnContainer As AnnContainer
   'AnnAutomationManager manager;
   Private viewer As RasterImageViewer
   Private codecs As RasterCodecs
   Public Sub New(ByVal title As String)
      Text = title
      Size = New Size(500, 200)

      viewer = New RasterImageViewer()
      viewer.Dock = DockStyle.Fill
      Controls.Add(viewer)
      viewer.BringToFront()

      ' load an image into the viewer
      RasterCodecs.Startup()
      codecs = New RasterCodecs()
      viewer.Image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "image1.cmp") ' fix this path to an existing image file on your system
      RasterCodecs.Shutdown()

      ' create and set up the container
      myAnnContainer = New AnnContainer()
      myAnnContainer.Bounds = New AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height)
      myAnnContainer.UnitConverter = New AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY)

      ' subscribe to the view PostTransformPaint and TransformChanged events to be able to correctly draw the container
      AddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaint
      AddHandler viewer.TransformChanged, AddressOf viewer_TransformChanged
      AddHandler viewer.MouseMove, AddressOf viewer_MouseMove

      ' add a few objects to the container
      Dim line As AnnLineObject = New AnnLineObject()
      line.Name = "Line1"
      line.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel))
      line.StartPoint = New AnnPoint(0, 0, AnnUnit.Pixel)
      line.EndPoint = New AnnPoint(100, 100, AnnUnit.Pixel)
      myAnnContainer.Objects.Add(line)

      Dim rect As AnnRectangleObject = New AnnRectangleObject()
      rect.Name = "Rectangle1"
      rect.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
      rect.Brush = New AnnSolidBrush(Color.White)
      rect.Bounds = New AnnRectangle(25, 25, 50, 50, AnnUnit.Pixel)
      myAnnContainer.Objects.Add(rect)

      ' repaint the viewer
      viewer.Invalidate(myAnnContainer.InvalidRectangle)
   End Sub

   Private Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)
      ' draw the container on top of the viewer
      myAnnContainer.Draw(e.Graphics)
   End Sub

   Private Sub viewer_TransformChanged(ByVal sender As Object, ByVal e As EventArgs)
      ' keep the container transform in synch with current viewer transformation (zoom, scroll, etc)
      myAnnContainer.Transform = viewer.Transform.Clone()
   End Sub

   Private Sub viewer_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
      ' perform hit-testing and update the status bar
      Dim pt As AnnPoint = New AnnPoint(e.X, e.Y, AnnUnit.Pixel)
      Dim obj As AnnObject = myAnnContainer.HitTest(pt, 2)
      If Not obj Is Nothing Then
         Text = String.Format("Type: {0}, Name: {1}, Value: {2}", obj.GetType().Name, obj.Name, obj.HitTest(pt, 2))
      Else
         Text = String.Empty
      End If
   End Sub
End Class




Private Sub AnnContainer_AnnContainer(ByVal title As String)
   Dim form As MyForm1 = New MyForm1(title)
   form.ShowDialog()
End Sub
C#Copy Code
class MyForm1 : Form 

   AnnContainer container; 
   //AnnAutomationManager manager; 
   RasterImageViewer viewer; 
   RasterCodecs codecs; 
   public MyForm1(string title) 
   { 
      Text = title; 
      Size = new Size(500, 200); 
 
      viewer = new RasterImageViewer(); 
      viewer.Dock = DockStyle.Fill; 
      Controls.Add(viewer); 
      viewer.BringToFront(); 
 
      // load an image into the viewer 
      RasterCodecs.Startup(); 
      codecs = new RasterCodecs(); 
      string fileName = LeadtoolsExamples.Common.ImagesPath.Path + "image1.cmp"; 
      viewer.Image = codecs.Load(fileName); 
      RasterCodecs.Shutdown(); 
 
      // create and set up the container 
      container = new AnnContainer(); 
      container.Bounds = new AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height); 
      container.UnitConverter = new AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY); 
 
      // subscribe to the view PostTransformPaint and TransformChanged events to be able to correctly draw the container 
      viewer.PostImagePaint += new PaintEventHandler(viewer_PostImagePaint); 
      viewer.TransformChanged += new EventHandler(viewer_TransformChanged); 
      viewer.MouseMove += new MouseEventHandler(viewer_MouseMove); 
 
      // add a few objects to the container 
      AnnLineObject line = new AnnLineObject(); 
      line.Name = "Line1"; 
      line.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel)); 
      line.StartPoint = new AnnPoint(0, 0, AnnUnit.Pixel); 
      line.EndPoint = new AnnPoint(100, 100, AnnUnit.Pixel); 
      container.Objects.Add(line); 
 
      AnnRectangleObject rect = new AnnRectangleObject(); 
      rect.Name = "Rectangle1"; 
      rect.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); 
      rect.Brush = new AnnSolidBrush(Color.White); 
      rect.Bounds = new AnnRectangle(25, 25, 50, 50, AnnUnit.Pixel); 
      container.Objects.Add(rect); 
 
      // repaint the viewer 
      viewer.Invalidate(container.InvalidRectangle); 
   } 
 
   private void viewer_PostImagePaint(object sender, PaintEventArgs e) 
   { 
      // draw the container on top of the viewer 
      container.Draw(e.Graphics); 
   } 
 
   private void viewer_TransformChanged(object sender, EventArgs e) 
   { 
      // keep the container transform in synch with current viewer transformation (zoom, scroll, etc) 
      container.Transform = viewer.Transform.Clone(); 
   } 
 
   private void viewer_MouseMove(Object sender, MouseEventArgs e) 
   { 
      // perform hit-testing and update the status bar 
      AnnPoint pt = new AnnPoint(e.X, e.Y, AnnUnit.Pixel); 
      AnnObject obj = container.HitTest(pt, 2); 
      if(obj != null) 
         Text = string.Format("Type: {0}, Name: {1}, Value: {2}", obj.GetType().Name, obj.Name, obj.HitTest(pt, 2)); 
      else 
         Text = string.Empty; 
   } 

 
 
 
 
private void AnnContainer_AnnContainer(string title) 

   MyForm1 form = new MyForm1(title); 
   form.ShowDialog(); 
}

Remarks

The annotation container is a rectangular area that holds annotation objects. The container is responsible for maintaining these objects as well as drawing them upon request.

Inheritance Hierarchy

System.Object
   Leadtools.Annotations.AnnContainer

Requirements

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

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features