Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.10.31
UserData Property
See Also  Example
Leadtools.Annotations Namespace > AnnObject Class : UserData Property




Gets or sets the user-defined data of this AnnObject.

Syntax

Visual Basic (Declaration) 
Public Overridable Property UserData As Object
Visual Basic (Usage)Copy Code
Dim instance As AnnObject
Dim value As Object
 
instance.UserData = value
 
value = instance.UserData
C# 
public virtual object UserData {get; set;}
Managed Extensions for C++ 
public: __property virtual Object* get_UserData();
public: __property virtual void set_UserData( 
   Object* value
);
C++/CLI 
public:
virtual property Object^ UserData {
   Object^ get();
   void set (Object^ value);
}

Return Value

The user-defined data of this AnnObject.

Example

This example will use a user-defined class to store extra information with each annotation object.

Visual BasicCopy Code
' 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
C#Copy Code
// 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; 
}

Remarks

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 SerializableAttribute and ISerializable interface.

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

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Raster Pro/Document/Medical Features