Gets or sets the object that contains data about this
RasterImageListItem.
Syntax
Visual Basic (Declaration) | |
---|
Public Property Tag As Object |
Visual Basic (Usage) | Copy Code |
---|
Dim instance As RasterImageListItem
Dim value As Object
instance.Tag = value
value = instance.Tag
|
C# | |
---|
public object Tag {get; set;} |
Managed Extensions for C++ | |
---|
public: __property Object* get_Tag();
public: __property void set_Tag(
Object* value
); |
Return Value
An
Object that contains data about this
RasterImageListItem. The default is a null reference
(Nothing in Visual Basic).
Example
This example creates and popluates an RasterImageList control with a few items, it then associates each item with
a user-defined object. When the selected item is changed by the user interface, the corresponding user data
is pulled from the selected item and shown in a message box.
Visual Basic | Copy Code |
---|
Private Class UserData
Public Number As Integer
Public Text As String
End Class
Public Sub RasterImageListItem_Tag(ByVal imageList As RasterImageList)
imageList.Bounds = New Rectangle(New Point(0, 0), New Size(300, 200))
imageList.Sorting = SortOrder.Ascending
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
imageList.Items.Clear()
Dim imagesPath As String = "C:\program files\LEAD Technologies\LEADTOOLS 15\Images\"
For i As Integer = 0 To 2
Dim index As Integer = i + 1
Dim imageFileName As String = imagesPath & "Image" & index.ToString() & ".cmp"
Dim image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
Dim item As RasterImageListItem = New RasterImageListItem(image, 1, "Item" & index.ToString())
If i = 0 Then
item.Selected = True
End If
Dim data As UserData = New UserData()
data.Number = index
data.Text = "This is data number " & index.ToString()
item.Tag = data
imageList.Items.Add(item)
Next i
AddHandler imageList.SelectedIndexChanged, AddressOf imageList_SelectedIndexChanged
RasterCodecs.Shutdown()
End Sub
Private Sub imageList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim imageList As RasterImageList = CType(IIf(TypeOf sender Is RasterImageList, sender, Nothing), RasterImageList)
Dim selectedItems As RasterImageListItemCollection = imageList.SelectedItems
If Not selectedItems Is Nothing AndAlso selectedItems.Count = 1 Then
Dim item As RasterImageListItem = selectedItems(0)
Dim data As UserData = CType(IIf(TypeOf item.Tag Is UserData, item.Tag, Nothing), UserData)
Dim msg As String = String.Format("Number = {0}{1}Text = {2}", data.Number, Environment.NewLine, data.Text)
MessageBox.Show(msg)
End If
End Sub |
C# | Copy Code |
---|
private class UserData { public int Number; public string Text; } public void RasterImageListItem_Tag(RasterImageList imageList) { // Create a new RasterImageList control. imageList.Bounds = new Rectangle(new Point(0, 0), new Size(300, 200)); // Sort the items in the list in ascending order. imageList.Sorting = SortOrder.Ascending; // Initialize the RasterCodecs class RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // Clear existing items imageList.Items.Clear(); // Create three items string imagesPath = @"C:\program files\LEAD Technologies\LEADTOOLS 15\Images\"; for (int i = 0; i < 3; i++) { // Load the image int index = i + 1; string imageFileName = imagesPath + "Image" + index.ToString() + ".cmp"; RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); RasterImageListItem item = new RasterImageListItem(image, 1, "Item" + index.ToString()); // Select the first item if (i == 0) item.Selected = true; // Add the user data UserData data = new UserData(); data.Number = index; data.Text = "This is data number " + index.ToString(); item.Tag = data; // Add the item to the image list imageList.Items.Add(item); } // Add a handler to the SelectedIndexChanged event imageList.SelectedIndexChanged += new EventHandler(imageList_SelectedIndexChanged); RasterCodecs.Shutdown(); } private void imageList_SelectedIndexChanged(object sender, EventArgs e) { // User has selected an item from the RasterImageList control. // Get the user data associated with the currently selected item and // show it in a message box RasterImageList imageList = sender as RasterImageList; // Get the selected item(s) RasterImageListItemCollection selectedItems = imageList.SelectedItems; if (selectedItems != null && selectedItems.Count == 1) { RasterImageListItem item = selectedItems[0]; // Load the image in its original size and set it in the viewer UserData data = item.Tag as UserData; string msg = string.Format("Number = {0}{1}Text = {2}", data.Number, Environment.NewLine, data.Text); MessageBox.Show(msg); } } |
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