Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private void DrawText(object sender, DrawItemEventArgs e, bool isSelected)
        {
            string    text    = VistaMenu.ShortcutToString(((MenuItem)sender).Shortcut);
            Rectangle bounds1 = e.Bounds;
            int       top     = bounds1.Top;

            bounds1 = e.Bounds;
            int       num     = (bounds1.Height - SystemFonts.MenuFont.Height) / 2;
            int       y       = top + num;
            Font      font    = ((MenuItem)sender).DefaultItem ? VistaMenu.menuBoldFont : SystemFonts.MenuFont;
            Size      size    = TextRenderer.MeasureText(((MenuItem)sender).Text, font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.SingleLine);
            Rectangle bounds2 = new Rectangle(e.Bounds.Left + 4 + 16 + 6, y, size.Width, size.Height);

            if (!((MenuItem)sender).Enabled && !isSelected)
            {
                bounds2.Offset(1, 1);
                TextRenderer.DrawText((IDeviceContext)e.Graphics, ((MenuItem)sender).Text, font, bounds2, SystemColors.ControlLightLight, (TextFormatFlags)(32 | (this.isUsingKeyboardAccel ? 0 : 1048576) | 256));
                bounds2.Offset(-1, -1);
            }
            TextRenderer.DrawText((IDeviceContext)e.Graphics, ((MenuItem)sender).Text, font, bounds2, ((MenuItem)sender).Enabled ? (isSelected ? SystemColors.HighlightText : SystemColors.MenuText) : SystemColors.GrayText, (TextFormatFlags)(32 | (this.isUsingKeyboardAccel ? 0 : 1048576) | 256));
            if (text == null)
            {
                return;
            }
            size    = TextRenderer.MeasureText(text, font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.SingleLine);
            bounds2 = new Rectangle(e.Bounds.Width - size.Width - 12, y, size.Width, size.Height);
            if (!((MenuItem)sender).Enabled && !isSelected)
            {
                bounds2.Offset(1, 1);
                TextRenderer.DrawText((IDeviceContext)e.Graphics, text, font, bounds2, SystemColors.ControlLightLight, (TextFormatFlags)(32 | (this.isUsingKeyboardAccel ? 0 : 1048576) | 256));
                bounds2.Offset(-1, -1);
            }
            TextRenderer.DrawText((IDeviceContext)e.Graphics, text, font, bounds2, ((MenuItem)sender).Enabled ? (isSelected ? SystemColors.HighlightText : SystemColors.MenuText) : SystemColors.GrayText, TextFormatFlags.NoClipping | TextFormatFlags.SingleLine);
        }
Ejemplo n.º 3
0
        /*
         * Create a notification context with an icon and menu.
         */
        internal NotificationContext() {
            // Create a VistaMenu control to stylize context menus
            VistaMenu vistaMenu = new VistaMenu();

            // Create menu items for the notification icon context menu
            MenuItem menuItemShow = new MenuItem("Show " + Application.ProductName, menuItemShow_Click);
            MenuItem menuItemSettings = new MenuItem("Settings…", menuItemSettings_Click);
            MenuItem menuItemAbout = new MenuItem("About…", menuItemAbout_Click);
            MenuItem menuItemExit = new MenuItem("Exit", menuItemExit_Click);

            // Add icons to the notification icon context menu items
            vistaMenu.SetImage(menuItemSettings, Properties.Resources.MenuItemSettings.ToBitmap());
            vistaMenu.SetImage(menuItemAbout, Properties.Resources.MenuItemAbout.ToBitmap());

            // Set the show menu entry as default (bold)
            menuItemShow.DefaultItem = true;

            // Add the menu items to the notify icon context menu
            ContextMenu contextMenuNotifyIcon = new ContextMenu(new MenuItem[] {
                menuItemShow,
                menuItemSettings,
                new MenuItem("-"),
                menuItemAbout,
                new MenuItem("-"),
                menuItemExit
            });

            // This needs to be called or the context menu will not have icons
            ((System.ComponentModel.ISupportInitialize)(vistaMenu)).EndInit();

            // Create a new instance of the notify icon
            notifyIcon = new NotifyIcon() {
                ContextMenu = contextMenuNotifyIcon,
                Icon = new Icon(Program.Settings.Data.WhiteNotificationIcon ?
                    Properties.Resources.NotificationWhite : Properties.Resources.NotificationColor,
                    SystemInformation.SmallIconSize),
                Text = Application.ProductName,
                Visible = true,
            };

            // Assign a click and double click event handler for the notification icon
            notifyIcon.Click += notifyIcon_Click;
            notifyIcon.DoubleClick += notifyIcon_DoubleClick;

            // Show the wrapper form on startup?
            if(Program.Settings.Data.ShowOnStartup) {
                DisplayWrapperForm();
            }

            // Remind the user that the application is running on the background?
            if(Program.Settings.Data.BackgroundRunningBalloon && !Program.Settings.Data.ShowOnStartup) {
                notifyIcon.BalloonTipClicked += delegate {
                    Program.Settings.Data.BackgroundRunningBalloon = false;
                };

                notifyIcon.ShowBalloonTip(3000, "SlackUI is running on the background",
                    "SlackUI started hidden and will continue to run so that you can receive real time updates while " +
                    "signed in.\n\nTo stop showing this reminder, click here.", ToolTipIcon.Info);
            }
        }
Ejemplo n.º 4
0
 private void AddVistaMenuItem(MenuItem mnuItem)
 {
     if (this.menuParents[(object)mnuItem.Parent] != null)
     {
         return;
     }
     if (mnuItem.Parent.GetType() == typeof(ContextMenu))
     {
         ((ContextMenu)mnuItem.Parent).Popup += new EventHandler(this.MenuItem_Popup);
     }
     else
     {
         ((MenuItem)mnuItem.Parent).Popup += new EventHandler(this.MenuItem_Popup);
     }
     VistaMenu.SetMenuInfo(new HandleRef((object)null, mnuItem.Parent.Handle), this.mnuInfo);
     this.menuParents[(object)mnuItem.Parent] = (object)true;
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
        private void MenuItem_Popup(object sender, EventArgs e)
        {
            MENUITEMINFO_T_RW lpmii = new MENUITEMINFO_T_RW();

            Menu.MenuItemCollection menuItemCollection = sender.GetType() == typeof(ContextMenu) ? ((Menu)sender).MenuItems : ((Menu)sender).MenuItems;
            int uItem = 0;

            for (int index = 0; index < menuItemCollection.Count; ++index)
            {
                if (menuItemCollection[index].Visible)
                {
                    Properties property = (Properties)this.properties[(object)menuItemCollection[index]];
                    if (property != null)
                    {
                        lpmii.hbmpItem = property.renderBmpHbitmap;
                        VistaMenu.SetMenuItemInfo(new HandleRef((object)null, ((Menu)sender).Handle), uItem, true, lpmii);
                    }
                    ++uItem;
                }
            }
        }
Ejemplo n.º 7
0
        private static void MenuItem_MeasureItem(object sender, MeasureItemEventArgs e)
        {
            Font font = ((MenuItem)sender).DefaultItem ? VistaMenu.menuBoldFont : SystemFonts.MenuFont;

            if (((MenuItem)sender).Text == "-")
            {
                e.ItemHeight = 9;
            }
            else
            {
                e.ItemHeight = (SystemFonts.MenuFont.Height > 16 ? SystemFonts.MenuFont.Height : 16) + 4;
                e.ItemWidth  = 26 + TextRenderer.MeasureText(((MenuItem)sender).Text, font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.SingleLine).Width + 20 + TextRenderer.MeasureText(VistaMenu.ShortcutToString(((MenuItem)sender).Shortcut), font, Size.Empty, TextFormatFlags.NoClipping | TextFormatFlags.SingleLine).Width + (((Menu)sender).IsParent ? 12 : 0);
            }
        }
Ejemplo n.º 8
0
        private static void SetImages(ContextMenu menu)
        {
            var vm = new VistaMenu();

            ((System.ComponentModel.ISupportInitialize)(vm)).BeginInit();

            foreach (MenuItem item in menu.MenuItems)
            {
                if (item.Tag is Task)
                {
                    switch ((item.Tag as Task).Priority)
                    {
                        case TaskPriority.One:
                            vm.SetImage(item, LazyCow.Properties.Resources.prio1);
                            break;
                        case TaskPriority.Two:
                            vm.SetImage(item, LazyCow.Properties.Resources.prio2);
                            break;
                        case TaskPriority.Three:
                            vm.SetImage(item, LazyCow.Properties.Resources.prio3);
                            break;
                        default:
                            vm.SetImage(item, LazyCow.Properties.Resources.prio0);
                            break;
                    }
                }
                else if (item.Tag is TaskList)
                {
                    foreach (MenuItem task in item.MenuItems)
                    {
                        if (!(task.Tag is Task)) continue;
                        var t = task.Tag as Task;

                        switch (t.Priority)
                        {
                            case TaskPriority.One:
                                vm.SetImage(task, LazyCow.Properties.Resources.prio1);
                                break;
                            case TaskPriority.Two:
                                vm.SetImage(task, LazyCow.Properties.Resources.prio2);
                                break;
                            case TaskPriority.Three:
                                vm.SetImage(task, LazyCow.Properties.Resources.prio3);
                                break;
                            default:
                                vm.SetImage(task, LazyCow.Properties.Resources.prio0);
                                break;
                        }
                    }
                }

            }

            ((System.ComponentModel.ISupportInitialize)(vm)).EndInit();
        }