예제 #1
0
        public void SetImage(MenuItem mnuItem, Image value)
        {
            Properties properties = this.EnsurePropertiesExists(mnuItem);

            properties.Image = value;
            if (!this.DesignMode && this.isVistaOrLater)
            {
                if (properties.renderBmpHbitmap != IntPtr.Zero)
                {
                    VistaMenu.DeleteObject(properties.renderBmpHbitmap);
                    properties.renderBmpHbitmap = IntPtr.Zero;
                }
                if (value == null)
                {
                    return;
                }
                using (Bitmap bitmap = new Bitmap(value.Width, value.Height, PixelFormat.Format32bppPArgb))
                {
                    using (Graphics graphics = Graphics.FromImage((Image)bitmap))
                        graphics.DrawImage(value, 0, 0, value.Width, value.Height);
                    properties.renderBmpHbitmap = bitmap.GetHbitmap(Color.FromArgb(0, 0, 0, 0));
                }
                if (this.formHasBeenIntialized)
                {
                    this.AddVistaMenuItem(mnuItem);
                }
            }
            if (this.DesignMode || this.isVistaOrLater || !this.formHasBeenIntialized)
            {
                return;
            }
            this.AddPreVistaMenuItem(mnuItem);
        }
예제 #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         foreach (DictionaryEntry property in this.properties)
         {
             if (((Properties)property.Value).renderBmpHbitmap != IntPtr.Zero)
             {
                 VistaMenu.DeleteObject(((Properties)property.Value).renderBmpHbitmap);
             }
         }
         if (this.components != null)
         {
             this.components.Dispose();
         }
     }
     base.Dispose(disposing);
 }