LEADTOOLS Annotations (Leadtools.Annotations assembly)
LEAD Technologies, Inc

UserData Property

Example 





Gets or sets the user-defined data of this AnnObject.
Syntax
public virtual object UserData {get; set;}
'Declaration
 
Public Overridable Property UserData As Object
'Usage
 
Dim instance As AnnObject
Dim value As Object
 
instance.UserData = value
 
value = instance.UserData
public virtual object UserData {get; set;}
 get_UserData();
set_UserData(value);
public:
virtual property Object^ UserData {
   Object^ get();
   void set (    Object^ value);
}

Property Value

The user-defined data of this AnnObject.
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 System.SerializableAttribute and System.Runtime.Serialization.ISerializable interface.
Example
 
' 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
// 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;
}
Requirements

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

See Also

Reference

AnnObject Class
AnnObject Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.