←Select platform

SelectedItemsChanged Event

Summary

Occurs when any of the items inside this viewer selection state changes.

Syntax
C#
C++/CLI
public event EventHandler SelectedItemsChanged 
public:  
   event EventHandler^ SelectedItemsChanged 
Remarks

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:

Item selection state changes in many ways:

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.

Example

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:

C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public ImageViewerForm _form = new ImageViewerForm(); 
public ImageViewer _imageViewer; 
 
public void SelectedItemsChanged_Example() 
{ 
 
   // Get the Form's ImageViewer control 
   _imageViewer = _form.ImageViewer; 
   // 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 viewer 
   using (var codecs = new RasterCodecs()) 
   { 
      for (var page = 1; page <= 4; page++) 
      { 
         var item = new ImageViewerItem(); 
         var fileName = Path.Combine(LEAD_VARS.ImagesDir, string.Format("ocr{0}.tif", page)); 
 
         // Create a thumbnail from the image 
         using (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 
   _imageViewer.SelectedItemsChanged += (sender, e) => 
   { 
      var sb = new StringBuilder(); 
      sb.Append("Selected indices:"); 
 
      // Get the selected items 
      var items = _imageViewer.Items.GetSelected(); 
      foreach (var item in items) 
         sb.Append(_imageViewer.Items.IndexOf(item) + " "); 
      Debug.WriteLine(sb.ToString()); 
   }; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Event Data
ParameterTypeDescription
senderobjectThe source of the event.
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.