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 container
private AnnContainer AnnObject_UserData()
{
// create the container and subclass to its Objects.ItemAdded event
AnnContainer container = new AnnContainer();
container.Objects.ItemAdded += new EventHandler<RasterCollectionEventArgs<AnnObject>>(Objects_ItemAdded);
// Add an item to the container
AnnEllipseObject 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 object
AnnObject obj = e.Item as AnnObject;
// store the current user name and date/time this object was created in the object
MyUserData userData = new MyUserData("MyUserName");
obj.UserData = userData;
}
Imports Leadtools
Imports Leadtools.Annotations
Imports Leadtools.Codecs
Imports Leadtools.WinForms
Imports Leadtools.Drawing
' This is the main method in your application to create a container
Private Function AnnObject_UserData() As AnnContainer
' create the container and subclass to its Objects.ItemAdded event
Dim container As AnnContainer = New AnnContainer()
AddHandler container.Objects.ItemAdded, AddressOf Objects_ItemAdded
' Add an item to the container
Dim 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 container
End 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 MyUserData
Public Sub New(ByVal userName_Renamed As String)
_userName = userName_Renamed
_dateCreated = DateTime.Now
End Sub
Private _userName As String
Public Property UserName() As String
Get
Return _userName
End Get
Set(ByVal value As String)
_userName = value
End Set
End Property
Private _dateCreated As DateTime
Public Property DateCreated() As DateTime
Get
Return _dateCreated
End Get
Set(ByVal value As DateTime)
_dateCreated = value
End Set
End Property
End Class
Private Sub Objects_ItemAdded(ByVal sender As Object, ByVal e As RasterCollectionEventArgs(Of AnnObject))
' get the object
Dim 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 object
Dim userData As MyUserData = New MyUserData("MyUserName")
obj.UserData = userData
End 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