【问题标题】:Imagelist with gifs带有 gif 的图像列表
【发布时间】:2013-08-09 14:55:42
【问题描述】:

我自己做了一个控件,这个控件允许加载一个图片。它里面预装了一些图片,我想让程序员使用这个控件来选择他们想要的图片。

我的第一次尝试是使用ImageList,但由于它不接受 GIF 图像,我需要一个解决方法。该控件在PictureBox 中显示GIF。

我的问题是:有什么方法可以像 ImageList 一样将图像作为属性公开给可视化 IDE(选择带有一点预览的 ComboBox 之类的图像)而不使用 Imagelist?

【问题讨论】:

  • 您必须制作自己的 UITypeEditor。
  • @HansPassant 谢谢,我找到了解决方案。

标签: c# .net vb.net .net-2.0 animated-gif


【解决方案1】:

如果有人需要解决方案:

<TypeConverter(GetType(ImageKeyConverter))> _
<RelatedImageList("LoadingImageList")> _
<Editor("System.Windows.Forms.Design.ImageIndexEditor, System.Design", GetType(Drawing.Design.UITypeEditor))> _
<Description("Imagen de carga que se mostrará en el control cuando se indique.")> _
Public Property LoadingImageKey() As String
    Get
        Return sPic
    End Get
    Set(ByVal value As String)
        sPic = value
    End Set
End Property

为了将 GIF 图像添加到 ImageList 中,我将它们添加到资源中,并在创建控件时将它们加载到 Imagelist 中。我有一个辅助变量来保存 GIFS,并且图像与字符串键相关:

Private Sub SysInfoControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim result As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, True, True)

    If pics.Count = 0 Then
        For Each elem As DictionaryEntry In result
            If elem.Value.GetType Is GetType(Bitmap) Then
                pics.Add(elem.Key.ToString(), CType(elem.Value, Bitmap))
                ImageList1.Images.Add(elem.Key.ToString(), CType(elem.Value, Bitmap))
            End If
        Next
        If pics.ContainsKey(sPic) Then picBoxLoading.Image = pics(sPic)
    End If
End Sub

结果示例:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2019-08-11
    • 2018-06-19
    • 2014-04-04
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    相关资源
    最近更新 更多