Exemple #1
0
 public MenuHelper(MenuItem item, Graphics graphics, MenuItemRender ext)
 {
     menuItem = item;
     extender = ext;
     iconSize = (ext.imageList == null) ? SystemInformation.SmallIconSize : ext.imageList.ImageSize;
     menuFont = (ext.useSystemFont || ext.menuFont == null) ? SystemInformation.MenuFont : ext.menuFont;
     gfx      = graphics;
 }
Exemple #2
0
 public ToolBox()
     : base()
 {
     this.SetStyle(ControlStyles.UserPaint, false);
     this.SetStyle(ControlStyles.StandardClick, false);
     this.SetStyle(ControlStyles.FixedWidth, false);
     this.Dock = DockStyle.None;
     this.buttonsCollection = new ToolBoxButtonCollection(this);
     this.renderer          = new MenuItemRender();
 }
Exemple #3
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService wfes = (IWindowsFormsEditorService)provider.GetService(
                typeof(IWindowsFormsEditorService));

            if (wfes == null || context == null)
            {
                return(null);
            }

            ImageList imageList = null;
            Component component = (Component)context.Instance;

            IExtenderListService extenderListService = (IExtenderListService)component.Site.GetService(typeof(IExtenderListService));

            if (extenderListService != null)
            {
                IExtenderProvider[] extenders = extenderListService.GetExtenderProviders();
                for (int i = 0; i < extenders.Length; i++)
                {
                    if (extenders[i].GetType().FullName == "MenuItemRenderer.MenuItemRenderer")
                    {
                        MenuItemRender menuExtender = (MenuItemRender)extenders[i];
                        imageList = menuExtender.ImageList;
                    }
                }
            }

            ImageSelector imageSelector = new ImageSelector(imageList, (int)value, wfes);

            wfes.DropDownControl(imageSelector);

            int imageIndex = -1;

            if (imageSelector.SelectedItems.Count != 0)
            {
                try
                {
                    imageIndex = (int)Convert.ToInt32(imageSelector.SelectedItems[0].Text);
                }
                catch
                {
                    imageIndex = -1;
                }
            }
            return(imageIndex);
        }
Exemple #4
0
        public override void PaintValue(PaintValueEventArgs pe)
        {
            int imageIndex = -1;

            if (pe.Value != null)
            {
                try
                {
                    imageIndex = (int)Convert.ToUInt16(pe.Value.ToString());
                }
                catch
                {
                    imageIndex = -1;
                }
            }

            if (pe.Context.Instance == null || imageIndex < 0)
            {
                return;
            }

            ImageList imageList = null;
            Component component = (Component)pe.Context.Instance;

            IExtenderListService extenderListService = (IExtenderListService)component.Site.GetService(typeof(IExtenderListService));

            if (extenderListService != null)
            {
                IExtenderProvider[] extenders = extenderListService.GetExtenderProviders();
                for (int i = 0; i < extenders.Length; i++)
                {
                    if (extenders[i].GetType().FullName == "MenuItemRenderer.MenuItemRenderer")
                    {
                        MenuItemRender menuExtender = (MenuItemRender)extenders[i];
                        imageList = menuExtender.ImageList;
                    }
                }
            }
            if (imageList == null ||
                imageList.Images.Empty ||
                imageIndex >= imageList.Images.Count)
            {
                return;
            }

            pe.Graphics.DrawImage(imageList.Images[imageIndex], pe.Bounds);
        }