【问题标题】:Re-Associating an ImageList with it's Keys将 ImageList 与其键重新关联
【发布时间】:2012-06-09 01:00:02
【问题描述】:

我有一个客户端和一个服务器。服务器从其桌面检索应用程序列表(每个都包含路径、名称和图标)。然后它将应用程序发送回客户端,以显示在带有 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 对象中都有应用程序的路径,那么如何将它们按顺序与图像列表中的相应图标关联起来?

【问题讨论】:

    标签: c# serialization icons client-server


    【解决方案1】:

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

    因此,我只需要使用

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

    带有要设置的图片的索引(对应应用)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多