LEADTOOLS WPF and Silverlight (Leadtools.Windows.Controls assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
AutoDisposeImages Property
See Also 
Leadtools.Windows.Controls Namespace > ImageList Class : AutoDisposeImages Property



Gets or sets a value indicating whether to auto dispose the old image when a new image is set into the items of this ImageList. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
<CategoryAttribute("Behavior")>
<DescriptionAttribute("Automatically disposes the item RasterImage objects when them item is removed from the control or when the control is disposed.")>
Public Property AutoDisposeImages As Boolean
Visual Basic (Usage)Copy Code
Dim instance As ImageList
Dim value As Boolean
 
instance.AutoDisposeImages = value
 
value = instance.AutoDisposeImages
C# 
[CategoryAttribute("Behavior")]
[DescriptionAttribute("Automatically disposes the item RasterImage objects when them item is removed from the control or when the control is disposed.")]
public bool AutoDisposeImages {get; set;}
C++/CLI 
[CategoryAttribute("Behavior")]
[DescriptionAttribute("Automatically disposes the item RasterImage objects when them item is removed from the control or when the control is disposed.")]
public:
property bool AutoDisposeImages {
   bool get();
   void set (    bool value);
}

Property Value

true if the Leadtools.RasterImage object in the items of this ImageList is automatically disposed when a new image is set; otherwise, false. Default value is true.

Example

Visual BasicCopy Code
Public Sub ImageList_AutoDisposeImages(ByVal imageList As ImageList)
      ' Make sure the AutoDisposeImages property is set to true 
      imageList.AutoDisposeImages = True
      MessageBox.Show("Removing an item then accessing its image with AutoDisposeImages set to true")
      ' Remove the first item 
      Dim item As RasterImageListItem = CType(imageList.Items(0), RasterImageListItem)
      imageList.Items.RemoveAt(0)

      ' Try to save this item's image into a disk file 
      ' This will throw an exception since the item image has been dispose 
      ' as a result of having the AutoDisposeImages false set to true 
      Dim codecs As New RasterCodecs()
      Try
         codecs.Save(item.Image, Path.Combine(LEAD_VARS.ImagesDir, "Test.jpg"), RasterImageFormat.Jpeg, 24)
         MessageBox.Show("Image saved correctly")
      Catch ex As Exception
         MessageBox.Show(ex.Message)
      End Try

      MessageBox.Show("Removing an item then accessing its image with AutoDisposeImages set to false")

      ' Now remove the next item, this time make sure to set the 
      ' AutoDisposeImages property to false before you remove the item 
      ' from the control collection 
      item = CType(imageList.Items(0), RasterImageListItem)

      imageList.AutoDisposeImages = False
      imageList.Items.RemoveAt(0)
      imageList.AutoDisposeImages = True

      ' Try to save this item's image into a disk file 
      ' This time, this should work correcly since the control did not dispose 
      ' the item image. 
      Try
         codecs.Save(item.Image, Path.Combine(LEAD_VARS.ImagesDir, "Test.jpg"), RasterImageFormat.Jpeg, 24)
         MessageBox.Show("Image saved correctly")
      Catch ex As Exception
         MessageBox.Show(ex.Message)
      End Try

      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void ImageList_AutoDisposeImages(ImageList imageList)
   {
      // Make sure the AutoDisposeImages property is set to true 
      imageList.AutoDisposeImages = true;
      MessageBox.Show("Removing an item then accessing its image with AutoDisposeImages set to true");
      // Remove the first item 
      RasterImageListItem item = imageList.Items[0] as RasterImageListItem;
      imageList.Items.RemoveAt(0);

      // Try to save this item's image into a disk file 
      // This will throw an exception since the item image has been dispose 
      // as a result of having the AutoDisposeImages false set to true 
      RasterCodecs codecs = new RasterCodecs();
      try
      {
         codecs.Save(item.Image, Path.Combine(LEAD_VARS.ImagesDir, "Test.jpg"), RasterImageFormat.Jpeg, 24);
         MessageBox.Show("Image saved correctly");
      }
      catch(Exception ex)
      {
         MessageBox.Show(ex.Message);
      }

      MessageBox.Show("Removing an item then accessing its image with AutoDisposeImages set to false");

      // Now remove the next item, this time make sure to set the 
      // AutoDisposeImages property to false before you remove the item 
      // from the control collection 
      item = imageList.Items[0] as RasterImageListItem;

      imageList.AutoDisposeImages = false;
      imageList.Items.RemoveAt(0);
      imageList.AutoDisposeImages = true;

      // Try to save this item's image into a disk file 
      // This time, this should work correcly since the control did not dispose 
      // the item image. 
      try
      {
         codecs.Save(item.Image, Path.Combine(LEAD_VARS.ImagesDir, "Test.jpg"), RasterImageFormat.Jpeg, 24);
         MessageBox.Show("Image saved correctly");
      }
      catch(Exception ex)
      {
         MessageBox.Show(ex.Message);
      }

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

When you change the value of this property, this control iterate all the items inside it and set the RasterImageListItem.AutoDisposeImages value of each item that is of type RasterImageListItem accordingly. For more information, refer to RasterImageListItem.AutoDisposeImages.

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also