←Select platform

RenderItemPlaceholder Method (ImageViewerVirtualizer)


Render any optional place holder before the image data is obtained.

abstract void RenderItemPlaceholder( 
   ImageViewerRenderEventArgs e 
virtual void RenderItemPlaceholder( 
      ImageViewerRenderEventArgs^ e 
   ) abstract 



Render event arguments to use.


This method is called while an item is being loaded and the image data has not been obtained yet.

Derived classes can render a visual hint to the user to indicate that the item is being loaded.

You should encapsulate the code inside this method with a try/catch and handle the error correctly. This method will not automatically fire the ItemError event.

using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
public ImageViewerForm _form = new ImageViewerForm(); 
public ImageViewer _imageViewer; 
public void ImageViewerVirtualizerExample() 
   // Get the input file name 
   string _imageFileName = imageFileName; 
   // Get the ImageViewer control from the form 
   _imageViewer = _form.ImageViewer; 
   // Set to vertical view layout 
   _imageViewer.ViewLayout = new ImageViewerVerticalViewLayout(); 
   // Add pan zoom interactive mode 
   _imageViewer.InteractiveModes.Add(new ImageViewerPanZoomInteractiveMode()); 
   // Add empty items, each one with the correct size but with no image data 
   // The virtualizer will take care of loading the pages and rendering them 
   using (RasterCodecs codecs = new RasterCodecs()) 
      int pageCount; 
      LeadSize pageSize; 
      LeadSizeD pageResolution; 
      using (CodecsImageInfo info = codecs.GetInformation(_imageFileName, true)) 
         pageCount = info.TotalPages; 
         pageSize = LeadSize.Create(info.Width, info.Height); 
         pageResolution = LeadSizeD.Create(info.XResolution, info.YResolution); 
      for (int page = 1; page <= pageCount; page++) 
         ImageViewerItem item = new ImageViewerItem(); 
         item.ImageSize = pageSize; 
         item.Resolution = pageResolution; 
      // Set the virtualizer to start loading the data into the empty items 
      _imageViewer.Virtualizer = new MyVirtualizer(_imageFileName); 
      // Hook to the VirtualizeItemReady to log each item as its image data is loaded 
      _imageViewer.VirtualizeItemReady += (Object sender, ImageViewerVirtualizerEventArgs e) => 
         System.Diagnostics.Debug.WriteLine("Image data for page " + (e.Item.RowIndex + 1) + " is ready");  
// Custom Virtualizer 
public class MyVirtualizer : ImageViewerVirtualizer 
   private string _imageFileName; 
   public MyVirtualizer(string imageFileName) : base() 
      _imageFileName = imageFileName; 
      // Load 4 items at a time 
      this.MaximumItems = 4; 
   protected override object LoadItem(ImageViewerItem item) 
      // Load a page, the page number is the item index, but it 
      // could be anything in the application, for example 
      // using ImageViewerItem.Tag to store the necessary data to identity this item 
      int pageNumber = this.ImageViewer.Items.IndexOf(item); 
      using (RasterCodecs codecs = new RasterCodecs()) 
         return codecs.Load(_imageFileName, pageNumber); 
   protected override void SaveItem(ImageViewerItem item, object data) 
      // Nothing to do in this application, just log it. 
      // If save is required, then this is the place to do it 
      int pageNumber = this.ImageViewer.Items.IndexOf(item); 
      System.Diagnostics.Debug.WriteLine("SaveItem for page " + pageNumber + " is called"); 
   protected override void DeleteItem(ImageViewerItem item, object data) 
      // Dispose the image 
      RasterImage image = data as RasterImage; 
      if (image != null) 
   protected override void RenderItemPlaceholder(ImageViewerRenderEventArgs e) 
      // Render the placeholder for this page 
      int pageNumber = this.ImageViewer.Items.IndexOf(e.Item) + 1; 
      LeadMatrix transform = this.ImageViewer.GetItemImageTransform(e.Item); 
      Graphics graphics = e.PaintEventArgs.Graphics; 
      // Render the message at 0,0 in this item transformation 
      LeadPointD pt = LeadPointD.Create(0, 0); 
      pt = transform.Transform(pt); 
      string message = string.Format("Loading page {0}...", pageNumber); 
      graphics.DrawString(message, this.ImageViewer.Font, Brushes.Black, (float)pt.X, (float)pt.Y); 

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.