Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
            }
        }