繁体   English   中英

重新将ImageList与它的键相关联

[英]Re-Associating an ImageList with it's Keys

我有一个客户端和一个服务器。 服务器从其桌面检索应用程序列表(每个包含路径,名称和图标)。 然后,它将应用程序发送回客户端,以使用LargeIcons在ListView中显示,以便客户端可以双击列表视图中的桌面图标,并在服务器上打开该应用程序。 (当完成以下错误时,此方法可以100%工作...)

但是,存在一个Microsoft错误,在该错误中,序列化的图标在反序列化时会降级( http://support.microsoft.com/kb/814735

我正在尝试遵循此处给出的建议,以恢复高质量的图标。

这是我在做什么:

//Get the list of Applications, which will include an icon, which we'll ignore due to the bug.
List<App> apps = client.ServiceProxy.getDesktopShortcuts();
// Get the ImageListStreamer (The serializable portion of the ImageList) and assign it to our Image List
ImageListStreamer il = client.ServiceProxy.getDesktopIcons();

foreach (App app in apps){
    ListViewItem item = new ListViewItem(app.name);
    item.ImageKey = app.path;
    lv.Items.Add(item);
}

当我将图标添加到getDesktopIcons()中的ImageList时,请按以下步骤操作:

il.Images.Add(app.path, app.icon);

从而使应用程序的路径成为关键。 但是,我相信当我仅将图像流发送回客户端时,它将丢失该关键信息。 我在每个App对象中都有该应用程序的路径,那么如何将它们与图像列表中的相应图标依次关联回去?

答案很简单。 由于我的List和ImageList的构建顺序相同,因此可以安全地假设当我循环浏览给出的应用程序时,Apps [0]将对应于ImageList [0]。

因此,我只需要简单地使用

il.Images.SetKeyName(i, app.path);

与要设置的图像索引(对应于应用程序)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM