Exemplo n.º 1
0
        /// <summary>
        /// Fetches an image of the requested size.
        /// </summary>
        /// <param name="size">Size of image to obtain.</param>
        /// <returns>If supported, returns requested image. A value of null
        /// indicates that the requested size is not supported.</returns>
        public virtual Image GetImage(ImageSize size)
        {
            if (DefaultImageProvider == null)
            {
                throw new NullReferenceException();
            }

            if (DefaultImageProvider == this)
            {
                Size iconSize   = IconImageProvider.GetIconSize(size);
                Icon iconResult = null;// new Icon(Resources.stop, iconSize);
                return(iconResult.ToBitmap());
            }

            return(DefaultImageProvider.GetImage(size));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Forces all images sizes to be refreshed from the respective providers.
        /// </summary>
        protected void RefreshItemImages()
        {
            Size imageSize = IconImageProvider.GetIconSize(ImageSize);

            ImageScalingSize = imageSize;

            bool           changesMade   = false;
            IImageProvider imageProvider = null;

            SuspendLayout();

            foreach (ToolStripItem item in Items)
            {
                if (item.Size != imageSize)
                {
                    imageProvider = null;

                    // If an image provider was registered with the toolstrip then...
                    if (ContainsImage(item))
                    {
                        if (IsImageSupported(item, ImageSize))
                        {
                            item.Image = GetImage(item, ImageSize);
                        }
                        else if (UseUnknownImageSizeIcon && IsImageSupported(ImageSize))
                        {
                            item.Image = GetImage(ImageSize);
                        }

                        changesMade = true;
                    }
                    else if (item is IImageProvider)
                    {
                        imageProvider = item as IImageProvider;
                    }
                    else if (item.Tag is IImageProvider)
                    {
                        imageProvider = item.Tag as IImageProvider;
                    }

                    // If an alternative image provider was found, attempt to use that.
                    if (!changesMade && imageProvider != null)
                    {
                        if (imageProvider.IsImageSupported(ImageSize))
                        {
                            item.Image  = imageProvider.GetImage(ImageSize);
                            changesMade = true;
                        }
                    }

                    // Were changes made?
                    if (changesMade)
                    {
                        // Automatically adjust the image scaling mode.
                        if (item.Image != null && item.Image.Size == imageSize)
                        {
                            item.ImageScaling = ToolStripItemImageScaling.None;
                        }
                        else
                        {
                            item.ImageScaling = ToolStripItemImageScaling.SizeToFit;
                        }
                    }
                }
            }

            ResumeLayout();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fetches an image of the requested size.
        /// </summary>
        /// <param name="size">Size of image to obtain.</param>
        /// <returns>If supported, returns requested image. A value of null
        /// indicates that the requested size is not supported.</returns>
        public Image GetImage(ImageSize size)
        {
            Icon desiredSize = new Icon(SourceIcon, IconImageProvider.GetIconSize(size));

            return(desiredSize.ToBitmap());
        }