コード例 #1
0
        /// <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="PSImgSet"/>
        /// </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
            PSImgSet imageSet = GetPSImgSet(context.Instance) ;

            // anything to show?
            if ((imageSet == null) || (imageSet.Count==0))
                return -1 ;

            // Create an image panel that is close to square
            Size dims = PSImgPanel.CalculateBestDimensions(imageSet.Count,PSImgPanel.PanelSizeHints.MinimizeBoth) ;
            imagePanel = new PSImgPanel((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 ;
        }
コード例 #2
0
        /// <summary>
        /// <see cref="PSImgPanel.ImageSelected"/> listener
        /// </summary>
        /// <param name="sender">The <see cref="PSImgPanel"/></param>
        /// <param name="e"><see cref="PSImgEventArgs"/> specifying the selection (or -1)</param>
        private void imagePanel_ImageSelected(object sender, EventArgs e)
        {
            // get the selection
            selectedIndex = ((PSImgEventArgs) e).ImageIndex ;
            // remove the listener
            imagePanel.ImageSelected -= new EventHandler(imagePanel_ImageSelected);
            // close the drop-dwon, we are done
            wfes.CloseDropDown() ;

            imagePanel.Dispose() ;
            imagePanel = null ;
        }