Gets or sets the object that contains data about this RasterImageListItem.
public object Tag {get; set;}Public Property Tag As ObjectAn System.Object that contains data about this RasterImageListItem. The default value is a null reference (Nothing in VB).
Any System.Object derived type can be assigned to this property.
You can use this property to associate your own user-defined data with an item.
This example creates and populates a 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 displayed in a message box.
Imports Leadtools.WinFormsImports LeadtoolsImports Leadtools.CodecsPrivate Class UserDataPublic Number As IntegerPublic Text As StringEnd ClassPublic Sub RasterImageListItem_Tag(ByVal imageList As RasterImageList)' 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 classDim codecs As RasterCodecs = New RasterCodecs()' Clear existing itemsimageList.Items.Clear()' Create three itemsDim imagesPath As String = LEAD_VARS.ImagesDirFor i As Integer = 0 To 2' Load the imageDim index As Integer = i + 1Dim imageFileName As String = Path.Combine(imagesPath, "ImageProcessingDemo\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())' Select the first itemIf i = 0 Thenitem.Selected = TrueEnd If' Add the user dataDim data As UserData = New UserData()data.Number = indexdata.Text = "This is data number " & index.ToString()item.Tag = data' Add the item to the image listimageList.Items.Add(item)Next i' Add a handler to the SelectedIndexChanged eventAddHandler imageList.SelectedIndexChanged, AddressOf imageList_SelectedIndexChangedEnd SubPrivate Sub imageList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)' 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 boxDim imageList As RasterImageList = CType(IIf(TypeOf sender Is RasterImageList, sender, Nothing), RasterImageList)' Get the selected item(s)Dim selectedItems As RasterImageListItemCollection = imageList.SelectedItemsIf Not selectedItems Is Nothing AndAlso selectedItems.Count = 1 ThenDim item As RasterImageListItem = selectedItems(0)' Load the image in its original size and set it in the viewerDim 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 IfEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools.WinForms;using Leadtools;using Leadtools.Codecs;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 classRasterCodecs codecs = new RasterCodecs();// Clear existing itemsimageList.Items.Clear();// Create three itemsstring imagesPath = LEAD_VARS.ImagesDir;for (int i = 0; i < 3; i++){// Load the imageint index = i + 1;string imageFileName = Path.Combine(imagesPath, @"ImageProcessingDemo\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 itemif (i == 0)item.Selected = true;// Add the user dataUserData data = new UserData();data.Number = index;data.Text = "This is data number " + index.ToString();item.Tag = data;// Add the item to the image listimageList.Items.Add(item);}// Add a handler to the SelectedIndexChanged eventimageList.SelectedIndexChanged += new EventHandler(imageList_SelectedIndexChanged);}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 boxRasterImageList 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 viewerUserData data = item.Tag as UserData;string msg = string.Format("Number = {0}{1}Text = {2}", data.Number, Environment.NewLine, data.Text);MessageBox.Show(msg);}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
|
Products |
Support |
Feedback: Tag Property - Leadtools.WinForms |
Introduction |
Help Version 19.0.2017.3.22
|

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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.