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
); |
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 Basic | Copy Code |
---|
Private Function AnnObject_UserData() As AnnContainer
Dim container As AnnContainer = New AnnContainer()
AddHandler container.Objects.ItemAdded, AddressOf Objects_ItemAdded
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
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))
Dim obj As AnnObject = CType(IIf(TypeOf e.Item Is AnnObject, e.Item, Nothing), AnnObject)
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
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