Leadtools.Annotations Namespace : AnnContainer Class |
[SerializableAttribute()] public class AnnContainer : System.IDisposable
'Declaration <SerializableAttribute()> Public Class AnnContainer Implements System.IDisposable
'Usage Dim instance As AnnContainer
public sealed class AnnContainer : IClosable //In WinRT the IDisposable interface is replaced by IClosable
function Leadtools.Annotations.AnnContainer()
[SerializableAttribute()] public ref class AnnContainer : public System.IDisposable
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
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"; }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2