/// <summary> /// When editing an image index value, let the user choose an image from /// a popup that displays all the images in the associated <see cref="ImageSet" /> /// </summary> /// <param name="context">designer context</param> /// <param name="provider">designer service provider</param> /// <param name="value">image index item</param> /// <returns>An image index (selected from the popup) or -1 if the user canceled the /// selection</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { wfes = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService)); if ((wfes == null) || (context == null)) { return(null); } // Get the image set ImageSet imageSet = GetImageSet(context.Instance); // anything to show? if ((imageSet == null) || (imageSet.Count == 0)) { return(-1); } // Create an image panel that is close to square Size dims = ImagePanel.CalculateBestDimensions(imageSet.Count, ImagePanel.PanelSizeHints.MinimizeBoth); imagePanel = new ImagePanel((Bitmap)imageSet.Preview, imageSet.Count, dims.Height, dims.Width); // set the current image index value as the default selection imagePanel.DefaultImage = (int)value; // no grid imagePanel.GridColor = Color.Empty; // listen for an image to be selected imagePanel.ImageSelected += new EventHandler(imagePanel_ImageSelected); // show the popup as a drop-down wfes.DropDownControl(imagePanel); // return the selection (or the original value if none selected) return((selectedIndex != -1) ? selectedIndex : (int)value); }