Represents an Annotation container.
Object Model
Syntax
Example
This example creates a new AnnContainer object, links it to a <see cref="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
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()
RasterCodecs.Startup()
codecs = New RasterCodecs()
viewer.Image = codecs.Load("C:\program files\LEAD Technologies\LEADTOOLS 15\Images\image1.cmp")
RasterCodecs.Shutdown()
myAnnContainer = New AnnContainer()
myAnnContainer.Bounds = New AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height)
myAnnContainer.UnitConverter = New AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY)
AddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaint
AddHandler viewer.TransformChanged, AddressOf viewer_TransformChanged
AddHandler viewer.MouseMove, AddressOf viewer_MouseMove
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)
viewer.Invalidate(myAnnContainer.InvalidRectangle)
End Sub
Private Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)
myAnnContainer.Draw(e.Graphics)
End Sub
Private Sub viewer_TransformChanged(ByVal sender As Object, ByVal e As EventArgs)
myAnnContainer.Transform = viewer.Transform.Clone()
End Sub
Private Sub viewer_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
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(); viewer.Image = codecs.Load(@"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\image1.cmp"); // fix this path to an existing image file on your system 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
Inheritance Hierarchy
Requirements
Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also