Gets or sets the user-defined data of this AnnObject.
public virtual object UserData { get; set; } Public Overridable Property UserData As Object
The user-defined data of this AnnObject.
You can use this property to store any extra data with this AnnObject. However, to allow functionality that depends on serialization (such as loading/saving from file or memory, copy/paste to/from clipboard, undo/redo buffers, etc), you must make sure the data type you use with this property is serializable. For more information on serialization, refer to the System.SerializableAttribute and System.Runtime.Serialization.ISerializable interface.
This example will use a user-defined class to store extra information with each annotation object.
using Leadtools;using Leadtools.Annotations;using Leadtools.Codecs;using Leadtools.WinForms;using Leadtools.Drawing;// This is the main method in your application to create a containerprivate AnnContainer AnnObject_UserData(){// create the container and subclass to its Objects.ItemAdded eventAnnContainer container = new AnnContainer();container.Objects.ItemAdded += new EventHandler<RasterCollectionEventArgs<AnnObject>>(Objects_ItemAdded);// Add an item to the containerAnnEllipseObject ellipse = new AnnEllipseObject();ellipse.Bounds = new AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel);ellipse.Pen = new AnnPen(Color.Green, new AnnLength(2, AnnUnit.Pixel));ellipse.Brush = new AnnSolidBrush(Color.Yellow);ellipse.Name = "Ellipse";container.Objects.Add(ellipse);return container;}// A private class in your application to store the user name as well as the date/time an annotation object was created.public class MyUserData{public MyUserData(string userName){_userName = userName;_dateCreated = DateTime.Now;}private string _userName;public string UserName{get{return _userName;}set{_userName = value;}}private DateTime _dateCreated;public DateTime DateCreated{get{return _dateCreated;}set{_dateCreated = value;}}}void Objects_ItemAdded(object sender, RasterCollectionEventArgs<AnnObject> e){// get the objectAnnObject obj = e.Item as AnnObject;// store the current user name and date/time this object was created in the objectMyUserData userData = new MyUserData("MyUserName");obj.UserData = userData;}
Imports LeadtoolsImports Leadtools.AnnotationsImports Leadtools.CodecsImports Leadtools.WinFormsImports Leadtools.Drawing' This is the main method in your application to create a containerPrivate Function AnnObject_UserData() As AnnContainer' create the container and subclass to its Objects.ItemAdded eventDim container As AnnContainer = New AnnContainer()AddHandler container.Objects.ItemAdded, AddressOf Objects_ItemAdded' Add an item to the containerDim ellipse As AnnEllipseObject = New AnnEllipseObject()ellipse.Bounds = New AnnRectangle(100, 100, 100, 100, AnnUnit.Pixel)ellipse.Pen = New AnnPen(Color.Green, New AnnLength(2, AnnUnit.Pixel))ellipse.Brush = New AnnSolidBrush(Color.Yellow)ellipse.Name = "Ellipse"container.Objects.Add(ellipse)Return containerEnd Function' A private class in your application to store the user name as well as the date/time an annotation object was created.Public Class MyUserDataPublic Sub New(ByVal userName_Renamed As String)_userName = userName_Renamed_dateCreated = DateTime.NowEnd SubPrivate _userName As StringPublic Property UserName() As StringGetReturn _userNameEnd GetSet(ByVal value As String)_userName = valueEnd SetEnd PropertyPrivate _dateCreated As DateTimePublic Property DateCreated() As DateTimeGetReturn _dateCreatedEnd GetSet(ByVal value As DateTime)_dateCreated = valueEnd SetEnd PropertyEnd ClassPrivate Sub Objects_ItemAdded(ByVal sender As Object, ByVal e As RasterCollectionEventArgs(Of AnnObject))' get the objectDim obj As AnnObject = CType(IIf(TypeOf e.Item Is AnnObject, e.Item, Nothing), AnnObject)' store the current user name and date/time this object was created in the objectDim userData As MyUserData = New MyUserData("MyUserName")obj.UserData = userDataEnd Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
