The AnnContainer Class is available in LEADTOOLS Document and Medical Imaging toolkits.
Represents an Annotation container.Visual Basic (Declaration) | |
---|---|
<SerializableAttribute()> Public Class AnnContainer Implements IDisposable |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As AnnContainer |
C# | |
---|---|
[SerializableAttribute()] public class AnnContainer : IDisposable |
C++/CLI | |
---|---|
[SerializableAttribute()] public ref class AnnContainer : public IDisposable |
This example creates a new AnnContainer object, links it to a Leadtools.WinForms.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 Basic | Copy 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 codecs = New RasterCodecs() viewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp")) ' fix this path to an existing image file on your system ' 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 Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class |
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 codecs = new RasterCodecs(); string fileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp"); viewer.Image = codecs.Load(fileName); // 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(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
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.
System.Object
Leadtools.Annotations.AnnContainer
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7