سؤال

I made my own control, and this control allows to have a image for loading. Its has some images preloaded inside, and I want to allow the programmers using this control to select which image they want.

My first try was to use a ImageList, but since it doesn't not accept GIFs images I need a workarround. The control shows the GIF in a PictureBox.

My question is: there is any way to expose the images to the visual IDE as a property in the same way that ImageList do (selecting images like a ComboBox with a little preview) without using a Imagelist?

هل كانت مفيدة؟

المحلول

Just if someone need the solution:

<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

And for adding the GIFs images into the ImageList, I added them to the resources and load them into the Imagelist on the creation of the control. I have a secondary var to hold the GIFS and the images are related with a string key:

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

Example of the result:

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top