none
How to edit UserControl attribute of type ImageList in Designer PropertyGrid (add/remove/exchange images)

    Question

  • I created a UserControl with some attributes to examine this question.

    public partial class MyControl: UserControl {
        public MyControl() {
            InitializeComponent();
        }
    
        [Browsable(true)]
        [Category("A Test")]
        [Description("A single image")]
        [DisplayName("Image")]
        public Image MyImage { get; set; } = null;
    
        [Browsable(true)]
        [Category("A Test")]
        [Description("Edit integer list")]
        [DisplayName("Integer List (List<int>)")]
        public List<int> MyListOfInt { get; set; } = new List<int>();
    
        [Browsable(true)]
        [Category("A Test")]
        [Description("Edit images list")]
        [DisplayName("Image List (List<Image>)")]
        public List<Image> MyListOfImages { get; set; } = new List<Image>();
        
        [Browsable(true)]
        [Category("A Test")]
        [Description("Edit images list")]
        [DisplayName("Image List (ImageList)")]
        public ImageList MyImageList { get; set; } = new ImageList();
    }

    In Designer this looks like:

    www.upload-pictures.de/bild.php/98278,imagelistattributeOG2WN.png

    By clicking on

    1. MyImage the 'Select resource' dialog is shown. OK

    2. MyListOfInt the 'Int32 Collection Editor' dialog is shown. OK

    3. MyListOfImages the 'Image Collection Editor' dialog is shown, but using the 'Add' button failes:

      'Cannot create an instance of System.Drawing.Image because it is an
        abstract class.'

    4. MyImageList shows an emtpy list, which cannot be edited.

    Did I neglect some attribute descriptor?
    Is it possible to tell VisualSTudio Designer to use the 'Select resource' dialog when clicking 'Add' button?


    Friday, July 29, 2016 5:44 AM

Answers

  • In case of method 4, it should be possible to drag a separate ImageList component to the same form. Then the “Image List (ImageList)" property of the User Control will contain “(none)” and the added ImageList. Select the image list, then expand the property and select the images. The images can be also edited for the ImageList component separately.

    Saturday, July 30, 2016 2:31 PM

All replies

  • In case of method 4, it should be possible to drag a separate ImageList component to the same form. Then the “Image List (ImageList)" property of the User Control will contain “(none)” and the added ImageList. Select the image list, then expand the property and select the images. The images can be also edited for the ImageList component separately.

    Saturday, July 30, 2016 2:31 PM
  • Yes, I think that's the shortest and easiest solution to this problem, thank you!
    Tuesday, August 02, 2016 8:57 AM