←Select platform

ItemError Event

Summary

Occurs when an error happens when the viewer tries to update the item image data.

Syntax
C#
C++/CLI
public event EventHandler<ImageViewerItemErrorEventArgs> ItemError 
public:  
   event EventHandler<Leadtools::Controls::ImageViewerItemErrorEventArgs^>^ ItemError 
Remarks

An error might occur if the image viewer is updating the image data of any of the items asynchronously or outside direct user programmatic interaction (such as during the drop part of a drag/drop operation). These operations do not occur from the user code (drop) or occur at a later time after they have been initiated (loading images asynchronously), therefore, the user must attach a handler to the ItemError event to be able to handle these errors.

When the value of ImageViewerItem.Url is set to a new value, the image viewer will use the current RasterCodecsInstance to load the image data asynchronously using RasterCodecs.LoadAsync or RasterCodecs.LoadSvgAsync. This can be triggered by any of the following:

If an error occurs, it fires the ItemError event will fire with the following values set in ImageViewerItemErrorEventArgs:

Member Value

Item

The item that triggered the error

Reason

ImageViewerItemChangedReason.Url

Data

Set to the instance of CodecsLoadAsyncCompletedEventArgs used internally by the viewer during LoadAsyncCompleted or LoadSvgAsyncCompleted.

Error

The exception thrown

RemoveEmptyItem

Set to true to automatically remove this item if it did not have previous data.

When an image or file system item is dragged and dropped over the viewer and System.Windows.Forms.Control.AllowDrop was set true, the viewer will try to automatically update or add a new item and load the new image data into it. An error might occur at this point and if so, the ItemError event will fire with the following values set in ImageViewerItemErrorEventArgs:

Member Value

Item

The item that triggered the error

Reason

ImageViewerItemChangedReason.Drop

Data

Set to the instance of ImageViewerItemDragDropEventArgs being used.

Error

The exception thrown

RemoveEmptyItem

Set to true to automatically remove this item if it did not have previous data.

Example
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 ImageViewerItemChangedExample() 
{ 
   // Get the Form's ImageViewer control 
   _imageViewer = _form.ImageViewer; 
 
   // ImageViewerItemChangedEventArgs reference 
   _imageViewer.ItemChanged += (sender, e) => 
   { 
      var item = e.Item; 
      var sb = new StringBuilder(); 
      sb.AppendFormat("ItemChanged:{0} Reason:{1} Size:{2} Res:{3}", _imageViewer.Items.IndexOf(item), e.Reason, item.Size, item.Resolution); 
      if (item.Image != null) 
         sb.AppendFormat(" Image: {0} bpp {1} by {2}", item.Image.BitsPerPixel, item.Image.Width, item.Image.Height); 
      else 
         sb.AppendFormat(" Image: null"); 
      Debug.WriteLine(sb.ToString()); 
 
      if (item.Url != null) 
         Debug.WriteLine("  Url:" + item.Url.ToString()); 
   }; 
 
   // ImageViewerItemErrorEventArgs reference 
   _imageViewer.ItemError += (sender, e) => 
   { 
      e.RemoveEmptyItem = false; 
      Debug.WriteLine("Data: {0}, Error: {1}", e.Data, e.Error); 
   }; 
 
   // Load an image 
   using (var codecs = new RasterCodecs()) 
      _imageViewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Event Data
ParameterTypeDescription
senderobjectThe source of the event.
eImageViewerItemErrorEventArgsThe event data.
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.