Occurs when any of the items inside this viewer selection state changes.
public event EventHandler SelectedItemsChanged Public Event SelectedItemsChanged As EventHandler public:event EventHandler^ SelectedItemsChanged
This event will occur when the value of ImageViewerItem.IsSelected of any of the items inside this image viewer changes. To get the selected items of the viewer:
Loop through the Items collection and check the IsSelected property of each item
Use the ImageViewerItems.GetSelected method that will return an array of the currently selected items.
Item selection state changes in many ways:
The IsSelected value of an item inside this viewer is changed programmatically.
If a selected item was removed from the viewer.
The ImageViewerItems.Select method is called.
The ImageViewerSelectItemsInteractiveMode is set in the viewer and is working.
When any of this occurs, the viewer will automatically re-renders the affected items and uses the "Selected" border, background and text color properties for any selected items. Besides this rendering behavior, the viewer does have treat selected items any differently and the selection state do not behave differently programmatically than any other item. Also there is no restriction on the number of items selected, you can select none, one or many items. For more information, refer to Image Viewer Items.
This example will use the viewer as a multi-selection enabled list of images and shows how to track the current selected items.
Start with the ImageViewer example, remove all the code inside the example function (search for the "// TODO: add example code here" comment) and insert the following code:
using Leadtools;using Leadtools.Controls;using Leadtools.Codecs;using Leadtools.Drawing;using LeadtoolsExamples.Common;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;public void SelectedItemsChanged_Example(){// Clear all the images already the viewer_imageViewer.Items.Clear();// Use vertical view layout_imageViewer.ViewLayout = new ImageViewerVerticalViewLayout();// Make sure the item size is larger than the image size (thumbnails mode)_imageViewer.ItemSize = LeadSize.Create(200, 200);_imageViewer.ImageBorderThickness = 1;// Change the selected item background color_imageViewer.SelectedItemBackgroundColor = Color.LightBlue;// Add 4 items to the viewerusing (var codecs = new RasterCodecs()){for (var page = 1; page <= 4; page++){var item = new ImageViewerItem();var fileName = Path.Combine(ImagesPath.Path, string.Format("ocr{0}.tif", page));// Create a thumbnail from the imageusing (var image = codecs.Load(fileName, page)){item.Image = image.CreateThumbnail(180, 180, 24, RasterViewPerspective.TopLeft, RasterSizeFlags.Resample);}_imageViewer.Items.Add(item);}}// Add the interface mode to select items (multiple)var selectItemsMode = new ImageViewerSelectItemsInteractiveMode();selectItemsMode.SelectionMode = ImageViewerSelectionMode.Multi;_imageViewer.DefaultInteractiveMode = selectItemsMode;// Hook to the SelectItemsChanged event and update the label_imageViewer.SelectedItemsChanged += (sender, e) =>{var sb = new StringBuilder();sb.Append("Selected indices:");// Get the selected itemsvar items = _imageViewer.Items.GetSelected();foreach (var item in items)sb.Append(_imageViewer.Items.IndexOf(item) + " ");_label.Text = sb.ToString();};}
Imports LeadtoolsImports Leadtools.ControlsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports LeadtoolsControlsExamples.LeadtoolsExamples.CommonPublic Sub SelectedItemsChanged_Example()' Clear all the images already the viewer_imageViewer.Items.Clear()' Use vertical view layout_imageViewer.ViewLayout = New ImageViewerVerticalViewLayout()' Make sure the item size is larger than the image size (thumbnails mode)_imageViewer.ItemSize = LeadSize.Create(200, 200)_imageViewer.ImageBorderThickness = 1' Change the selected item background color_imageViewer.SelectedItemBackgroundColor = Color.LightBlue' Add 4 items to the viewerUsing codecs As New RasterCodecs()For page As Integer = 1 To 4Dim item As New ImageViewerItem()Dim fileName As String = Path.Combine(ImagesPath.Path, String.Format("ocr{0}.tif", page))' Create a thumbnail from the imageUsing image As RasterImage = codecs.Load(fileName, page)item.Image = image.CreateThumbnail(180, 180, 24, RasterViewPerspective.TopLeft, RasterSizeFlags.Resample)End Using_imageViewer.Items.Add(item)Next pageEnd Using' Add the interface mode to select items (multiple)Dim selectItemsMode As New ImageViewerSelectItemsInteractiveMode()selectItemsMode.SelectionMode = ImageViewerSelectionMode.Multi_imageViewer.DefaultInteractiveMode = selectItemsMode' Hook to the SelectItemsChanged event and update the labelAddHandler _imageViewer.SelectedItemsChanged,Sub(sender, e)Dim sb As New StringBuilder()sb.Append("Selected indices:")' Get the selected itemsDim items() As ImageViewerItem = _imageViewer.Items.GetSelected()For Each item As ImageViewerItem In itemssb.Append(_imageViewer.Items.IndexOf(item) & " ")Next item_label.Text = sb.ToString()End SubEnd Sub
| Parameter | Type | Description |
|---|---|---|
| sender | object | The source of the event. |
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
