我在写标题时遇到了一个问题。
我将ListView用于文件资源管理器,并且有很多图像文件。
当我替换相同名称的图像文件时,需要解决的问题。
问题:
注意:
我的错误代码:
il16.Images.RemoveByKey( fi.FullName );
il32.Images.RemoveByKey( fi.FullName );
il32FullSize.Images.RemoveByKey( fi.FullName );
item.ImageKey = AddImageKey( fi.FullName, false );
我的AddImageKey函数正常工作:
public String AddImageKey( String Location, bool IsDirectory, bool UseDefault = false )
{
String Retval = "";
if ( IsDirectory )
{
Retval = "<DIR>";
if ( !AddedExtensions.Contains( Retval ) )
{
Icon img = this.win32.GetIcon( Directory.GetCurrentDirectory().ToString(), true );
il16.Images.Add( Retval, img );
img = this.win32.GetIcon( Directory.GetCurrentDirectory().ToString(), false );
il32.Images.Add( Retval, img );
img = this.win32.GetIcon( Directory.GetCurrentDirectory().ToString(), false );
il32FullSize.Images.Add( Retval, img );
AddedExtensions.Add( Retval );
}
}
else
{
FileInfo fi = new FileInfo( Location );
try
{
if ( UseDefault )
{
throw new Exception("Use Default Icon");
}
if ( !AddedImages.Contains( fi.FullName ) )
{
Image img = Image.FromFile( fi.FullName );
il16.Images.Add( fi.FullName, img.GetThumbnailImage( 16, 16, null, new IntPtr()) );
il32.Images.Add( fi.FullName, img.GetThumbnailImage( 128, 128, null, new IntPtr() ) );
il32FullSize.Images.Add( fi.FullName, img.GetThumbnailImage( 128, 128, null, new IntPtr() ) );
img.Dispose();
AddedImages.Add( fi.FullName );
}
Retval = fi.FullName;
}
catch
{
if ( !AddedExtensions.Contains( fi.Extension ) )
{
Icon img = this.win32.GetIcon( fi.FullName, true );
il16.Images.Add( GetExt( fi.FullName ), img );
img = this.win32.GetIcon( fi.FullName, false );
il32.Images.Add( GetExt( fi.FullName ), img );
il32FullSize.Images.Add( GetExt( fi.FullName ), img );
AddedExtensions.Add( fi.Extension );
}
Retval = fi.Extension;
}
}
return Retval;
}