Пример #1
0
        /// <summary>
        /// Draws a menu glyph with the specified colors.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect">The <c>System.Drawing.Graphics</c> object to draw on.</param>
        /// <param name="foreColor">The <c>System.Drawing.Color</c> that represents the foreground color.</param>
        /// <param name="backColor">The <c>System.Drawing.Color</c> that represents the background color.</param>
        private void DrawMenuGlyph(Graphics g, Rectangle rect, Color foreColor, Color backColor)
        {
            Graphics  offscreen    = null;
            Bitmap    image        = null;
            Rectangle offsceenRect = new Rectangle(0, 0, rect.Width, rect.Height);

            //
            // Render glyph to offscreen bitmap, then swap colors
            //
            try
            {
                image     = new Bitmap(rect.Width, rect.Height);
                offscreen = Graphics.FromImage(image);

                ControlPaint.DrawMenuGlyph(offscreen, offsceenRect, this.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark);

                DrawImage(g, image, rect, Color.White, backColor, Color.Black, foreColor);
            }
            finally
            {
                if (offscreen != null)
                {
                    offscreen.Dispose();
                }
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }
Пример #2
0
        private void DataGridViewProfiles_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            // Check rows have been drawn and cell is in profile activation column
            if (IsRowIndexValid(e.RowIndex, true) && e.ColumnIndex == columnActive.Index)
            {
                // Print cell background without selection highlight
                e.PaintBackground(e.ClipBounds, false);

                // Print checkmark in cell if checked
                if (IsCellChecked(e.RowIndex, e.ColumnIndex))
                {
                    Rectangle rectangle = new Rectangle(
                        e.CellBounds.X + (e.CellBounds.Width - 13) / 2,
                        e.CellBounds.Y + (e.CellBounds.Height - 17) / 2,
                        17,
                        17
                        );
                    ControlPaint.DrawMenuGlyph(e.Graphics, rectangle, MenuGlyph.Checkmark);
                }

                // Paint focus rectangle around cell
                e.Paint(e.ClipBounds, DataGridViewPaintParts.Focus);

                // Prevent event propagation
                e.Handled = true;
            }
        }
Пример #3
0
        /// <summary>
        /// 绘制复选控件的图案
        /// </summary>
        /// <param g="Graphics">封装一个绘图的类对象</param>
        /// <param rect="Rectangle">单选图案的绘制区域</param>
        /// <param Above="bool">断判鼠标是否在控件上方</param>
        private void DrawBox(Graphics g, Rectangle rect, bool Above)
        {
            //设置外椭圆的渐变色
            int opacity = Measurement;

            //根据一个矩形、起始颜色和结束颜色以及方向,创建LinearGradientBrush 类的实例,用于设置外椭圆的渐变色
            Periphery_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 2, PeripheryColor), Color.FromArgb(opacity, PeripheryColor), LinearGradientMode.ForwardDiagonal);
            int size = this.Font.Height;//获取字体的高度
            //获取外椭圆的区域
            Rectangle box   = new Rectangle(rect.X + ((rect.Width - size) / 2), rect.Y + ((rect.Height - size) / 2), size - 2, size - 2);
            Rectangle glyph = new Rectangle(box.X + 3, box.Y + 3, box.Width - 6, box.Height - 6);//设置内圆的绘制区域
            Rectangle right = new Rectangle(box.X, box.Y - 1, box.Width + 2, box.Height + 2);

            g.FillEllipse(new SolidBrush(SystemColors.Window), box); //以白色填充单选图案

            if (this.CheckState == CheckState.Checked)               //如果是选中状态
            {
                base.ForeColor = Color.DarkBlue;
                ControlPaint.DrawMenuGlyph(g, right, MenuGlyph.Checkmark, this.StippleColor, Color.White); //绘制对号
                g.DrawRectangle(new Pen(new SolidBrush(SystemColors.Control), (float)(3)), box);           //绘制外椭圆
            }
            if (this.CheckState == CheckState.Indeterminate)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(127, SystemColors.Control)), right);
            }
            g.DrawRectangle(new Pen(Periphery_br, (float)(1.5)), box);//绘制外椭圆
        }
Пример #4
0
        private void DrawCheckmark(Graphics g, Rectangle bounds, bool selected)
        {
            int checkTop  = bounds.Top + (itemHeight - BITMAP_SIZE) / 2;
            int checkLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE) / 2;

            ControlPaint.DrawMenuGlyph(g, new Rectangle(checkLeft, checkTop, BITMAP_SIZE, BITMAP_SIZE), MenuGlyph.Checkmark);
            g.DrawRectangle(new Pen(framecolor), checkLeft - 1, checkTop - 1, BITMAP_SIZE + 1, BITMAP_SIZE + 1);
        }
        protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
        {
            Rectangle glyphBounds = e.ImageRectangle;
            Color     tableColor;
            Color     defaultColor;

            if (e.Item.Enabled)
            {
                if (e.Item.Selected)
                {
                    tableColor   = colorTable.HighlightForeColor;
                    defaultColor = ToolStripSystemColorTable.DefaultHighlightForeColor;
                }
                else
                {
                    tableColor   = colorTable.HighlightForeColor;
                    defaultColor = ToolStripSystemColorTable.DefaultHighlightForeColor;
                }
            }
            else
            {
                tableColor   = colorTable.DisabledForeColor;
                defaultColor = ToolStripSystemColorTable.DefaultDisabledForeColor;
            }

            if (tableColor != defaultColor)
            {
                ControlPaint.DrawMenuGlyph(e.Graphics, glyphBounds, MenuGlyph.Checkmark, tableColor, Color.Transparent);
            }
            else if (ToolStripManager.VisualStylesEnabled)
            {
                VisualStyleElement backVSElement  = GetMenuGlyphBackgroundVSElement(e.Item.Enabled, false);
                VisualStyleElement glyphVSElement = GetMenuGlyphVSElement(MenuGlyph.Checkmark, e.Item.Enabled);
                if (VisualStyleRenderer.IsElementDefined(backVSElement) && VisualStyleRenderer.IsElementDefined(glyphVSElement))
                {
                    //We use Inflate in order to keep the rectangle centered with the glyph.
                    int       inflation  = ((e.Item.Height - e.ImageRectangle.Height) / 2);
                    Rectangle backBounds = glyphBounds;
                    backBounds.Inflate(inflation, inflation);
                    DrawVisualStyle(e.Graphics, backVSElement, backBounds);
                    DrawVisualStyle(e.Graphics, glyphVSElement, glyphBounds);
                }
                else
                {
                    base.OnRenderItemCheck(e);
                }
            }
            else
            {
                base.OnRenderItemCheck(e);
            }
        }
        protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
        {
            Color tableColor;
            Color defaultColor;

            if (e.Item.Enabled)
            {
                if (e.Item.Selected)
                {
                    tableColor   = colorTable.HighlightForeColor;
                    defaultColor = ToolStripSystemColorTable.DefaultHighlightForeColor;
                }
                else
                {
                    tableColor   = colorTable.HighlightForeColor;
                    defaultColor = ToolStripSystemColorTable.DefaultHighlightForeColor;
                }
            }
            else
            {
                tableColor   = colorTable.DisabledForeColor;
                defaultColor = ToolStripSystemColorTable.DefaultDisabledForeColor;
            }

            if (tableColor != defaultColor)
            {
                ControlPaint.DrawMenuGlyph(e.Graphics, e.ArrowRectangle, MenuGlyph.Arrow, tableColor, Color.Transparent);
            }
            else if (ToolStripManager.VisualStylesEnabled)
            {
                VisualStyleElement vsElement = GetMenuGlyphVSElement(MenuGlyph.Arrow, e.Item.Enabled);
                if (VisualStyleRenderer.IsElementDefined(vsElement))
                {
                    VisualStyleRenderer vsRenderer = GetVisualStyleRenderer(vsElement);
                    //Creates the appropriate rectangle for the arrow (e.ArrowRectangle is too big!)
                    Rectangle arrowRect = new Rectangle(e.ArrowRectangle.Location, vsRenderer.GetPartSize(e.Graphics, ThemeSizeType.True));
                    //Centers the rectangle vertically
                    arrowRect.Y = e.ArrowRectangle.Y + (e.ArrowRectangle.Height - arrowRect.Height) / 2 + 1; //+1 is just a quick empirical adjustement.
                    vsRenderer.DrawBackground(e.Graphics, arrowRect);
                }
                else
                {
                    base.OnRenderArrow(e);
                }
            }
            else
            {
                base.OnRenderArrow(e);
            }
        }
Пример #7
0
        private void DrawGlypth2(Graphics graphics)
        {
            Color foreColor;

            if ((this.RightToLeft != RightToLeft.Yes && this.IsNextMonthInRange()) ||
                (this.RightToLeft == RightToLeft.Yes && this.IsPrevMonthInRange()))
            {
                foreColor = this.titleForeColor;
            }
            else
            {
                // foreColor = SystemColors.GrayText;
                return;
            }
            ControlPaint.DrawMenuGlyph(graphics, this.glyph2Bounds, MenuGlyph.Arrow, foreColor,
                                       this.titleBackColor);
        }
Пример #8
0
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        e.DrawBackground();

        if ((e.State & DrawItemState.Checked) != 0)
        {
            ControlPaint.DrawMenuGlyph(e.Graphics,
                                       e.Bounds.Location.X + iMargin,
                                       e.Bounds.Location.Y + iMargin,
                                       cxImage, cyImage, MenuGlyph.Checkmark);
        }
        HatchBrush hbrush = new HatchBrush(HatchStyle, Color.White, Color.Black);

        e.Graphics.FillRectangle(hbrush,
                                 e.Bounds.X + 2 * iMargin + cxImage,
                                 e.Bounds.Y + iMargin, cxImage, cyImage);
    }
Пример #9
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (DrawItem != null)
            {
                DrawItem(this, e);
            }
            Font      drawFont = e.Font;
            Rectangle check    = new Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height);

            if (this.CheckedIndices.Contains(e.Index))
            {
                ControlPaint.DrawMenuGlyph(e.Graphics, check, MenuGlyph.Checkmark, this.ForeColor, Color.Transparent);
            }
            Rectangle checkBox = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Height - 6, e.Bounds.Height - 6);

            e.Graphics.DrawRectangle(new Pen(this.ForeColor), checkBox);
        }
Пример #10
0
    void MenuFacenameOnDrawItem(object obj, DrawItemEventArgs diea)
    {
        MenuItem mi   = (MenuItem)obj;
        Graphics grfx = diea.Graphics;
        Brush    brush;

        // Create the Font and StringFormat.

        Font         font   = new Font(mi.Text.Substring(1), iFontPointSize);
        StringFormat strfmt = new StringFormat();

        strfmt.HotkeyPrefix = HotkeyPrefix.Show;

        // Calculate check mark and text rectangles.

        Rectangle rectCheck = diea.Bounds;

        rectCheck.Width = SystemInformation.MenuCheckSize.Width *
                          rectCheck.Height /
                          SystemInformation.MenuCheckSize.Height;

        Rectangle rectText = diea.Bounds;

        rectText.X += rectCheck.Width;

        // Do all the drawing.

        diea.DrawBackground();

        if ((diea.State & DrawItemState.Checked) != 0)
        {
            ControlPaint.DrawMenuGlyph(grfx, rectCheck, MenuGlyph.Bullet);
        }

        if ((diea.State & DrawItemState.Selected) != 0)
        {
            brush = SystemBrushes.HighlightText;
        }
        else
        {
            brush = SystemBrushes.FromSystemColor(SystemColors.MenuText);
        }

        grfx.DrawString(mi.Text, font, brush, rectText, strfmt);
    }
Пример #11
0
    void MenuFacenameOnDrawItem(object obj, DrawItemEventArgs diea)
    {
        MenuItem mi   = (MenuItem)obj;
        Graphics grfx = diea.Graphics;
        Brush    brush;

        // Создание Font и StringFormat.

        Font         font   = new Font(mi.Text.Substring(1), iFontPointSize);
        StringFormat strfmt = new StringFormat();

        strfmt.HotkeyPrefix = HotkeyPrefix.Show;

        // Вычисление прямоугольников флажка и текста

        Rectangle rectCheck = diea.Bounds;

        rectCheck.Width = SystemInformation.MenuCheckSize.Width *
                          rectCheck.Height /
                          SystemInformation.MenuCheckSize.Height;

        Rectangle rectText = diea.Bounds;

        rectText.X += rectCheck.Width;

        // Выполняем все рисование

        diea.DrawBackground();

        if ((diea.State & DrawItemState.Checked) != 0)
        {
            ControlPaint.DrawMenuGlyph(grfx, rectCheck, MenuGlyph.Bullet);
        }

        if ((diea.State & DrawItemState.Selected) != 0)
        {
            brush = SystemBrushes.HighlightText;
        }
        else
        {
            brush = SystemBrushes.FromSystemColor(SystemColors.MenuText);
        }

        grfx.DrawString(mi.Text, font, brush, rectText, strfmt);
    }
Пример #12
0
 private void DrawGlyph(PaintEventArgs pevent)
 {
     using (var image = new Bitmap(glyphBounds.Width, glyphBounds.Height)) {
         using (var graphics = Graphics.FromImage(image)) {
             ControlPaint.DrawMenuGlyph(graphics, 2, 0, glyphBounds.Width, glyphBounds.Height,
                                        MenuGlyph.Arrow, this.ForeColor, Color.Transparent);
         }
         image.RotateFlip(RotateFlipType.Rotate90FlipNone);
         if (!this.Enabled)
         {
             ControlPaint.DrawImageDisabled(pevent.Graphics, image, glyphBounds.X, glyphBounds.Y, Color.Transparent);
         }
         else
         {
             pevent.Graphics.DrawImage(image, glyphBounds);
         }
     }
 }
Пример #13
0
            private void DrawCheck(Graphics graphics, Rectangle rectangle, Color color)
            {
                Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height);

                Graphics bitmapGraphics = Graphics.FromImage(bitmap);

                ControlPaint.DrawMenuGlyph(bitmapGraphics, 0, 0, rectangle.Width, rectangle.Height, MenuGlyph.Checkmark);
                bitmapGraphics.Flush();

                bitmap.MakeTransparent(Color.White);

                ImageAttributes attributes = new ImageAttributes();
                ColorMap        colorMap   = new ColorMap();

                colorMap.OldColor = Color.Black;
                colorMap.NewColor = color;
                attributes.SetRemapTable(new ColorMap[] { colorMap });

                graphics.DrawImage(bitmap, rectangle, 0, 0, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel, attributes);
            }
Пример #14
0
        private void ControlPaintTest_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(10, 10, 50, 50), ButtonState.Checked);
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(70, 10, 30, 30), ButtonState.Normal);
            ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(110, 10, 20, 20), ButtonState.Checked);

            ControlPaint.DrawButton(e.Graphics, new Rectangle(10, 80, 20, 20), ButtonState.Checked);
            ControlPaint.DrawButton(e.Graphics, new Rectangle(50, 80, 20, 20), ButtonState.Flat);
            ControlPaint.DrawButton(e.Graphics, new Rectangle(90, 80, 20, 20), ButtonState.Normal);
            ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(130, 80, 20, 20));

            ControlPaint.DrawGrid(e.Graphics, new Rectangle(10, 120, 250, 50), new Size(5, 5), Color.Blue);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(10, 180, 20, 20), ScrollButton.Left, ButtonState.Normal);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(50, 180, 20, 20), ScrollButton.Max, ButtonState.Pushed);
            ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(90, 180, 20, 20), ScrollButton.Up, ButtonState.Normal);

            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(10, 220, 20, 20), MenuGlyph.Arrow);
            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(50, 220, 20, 20), MenuGlyph.Checkmark);
            ControlPaint.DrawMenuGlyph(e.Graphics, new Rectangle(90, 220, 20, 20), MenuGlyph.Max);
        }
Пример #15
0
 // 功能名称:       DrawCheckmark(画菜单选项)
 // 参数说明:
 // bounds          菜单项前面表示选中的小方块
 // selected        boolean型,表示是否选中
 public void DrawCheckmark(Graphics g, Rectangle bounds, bool selected)
 {
     try
     {
         if (((ContextMenuStrip)base.Parent).ShowCheckMargin)
         {
             ControlPaint.DrawMenuGlyph(g, new Rectangle(bounds.X + 26, bounds.Y + base.Padding.Top, 14, 14), MenuGlyph.Checkmark, Color.Black, Color.White);
             if (!(base.Image == null))
             {
             }
         }
         else
         {
             ControlPaint.DrawMenuGlyph(g, new Rectangle(bounds.X + 4, bounds.Y + base.Padding.Top, 14, 14), MenuGlyph.Checkmark, Color.Black, Color.White);
         }
     }
     catch (Exception ex)
     {
     }
 }
        /// <summary>
        /// 绘制复选框控件的图案
        /// </summary>
        /// <param g="Graphics">封装一个绘图的类对象</param>
        /// <param rect="Rectangle">复选框图案的绘制区域</param>
        /// <param Above="bool">断判鼠标是否在控件上方</param>
        private void DrawBox(Graphics g, Rectangle rect, bool Above)
        {
            //设置外椭圆的渐变色
            int opacity = Measurement;

            Periphery_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 2, PeripheryColor), Color.FromArgb(opacity, PeripheryColor), LinearGradientMode.ForwardDiagonal);
            //设置中间椭圆形选中时的渐变色
            opacity    = (int)(.4f * opacity + .5f);
            Central_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 10, CentralColor), Color.FromArgb(opacity, CentralColor), LinearGradientMode.ForwardDiagonal);
            //设置中间椭圆形无操作时的渐变色
            opacity      = (int)(.4f * opacity + .5f);
            NoCentral_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 10, NoCentralColor), Color.FromArgb(opacity, NoCentralColor), LinearGradientMode.ForwardDiagonal);
            int size = this.Font.Height;//获取字体的高度
            //获取外椭圆的区域
            Rectangle box   = new Rectangle(rect.X + ((rect.Width - size) / 2), rect.Y + ((rect.Height - size) / 2), size - 2, size - 2);
            Rectangle glyph = new Rectangle(box.X + 3, box.Y + 3, box.Width - 6, box.Height - 6);//设置内圆的绘制区域
            Rectangle right = new Rectangle(box.X, box.Y - 1, box.Width + 2, box.Height + 2);

            g.FillEllipse(new SolidBrush(SystemColors.Window), box); //以白色填充图案

            if (this.CheckState == CheckState.Checked)               //如果是选中状态
            {
                base.ForeColor = Color.DarkBlue;
                ControlPaint.DrawMenuGlyph(g, right, MenuGlyph.Checkmark, this.StippleColor, Color.White); //绘制对号
                g.DrawRectangle(new Pen(new SolidBrush(SystemColors.Control), (float)(3)), box);           //绘制外椭圆
            }
            if (this.CheckState == CheckState.Indeterminate)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(127, SystemColors.Control)), right);
            }

            if (Above && this.Enabled)                                                                                       //如果鼠标移入该控件
            {
                g.DrawRectangle(new Pen(Central_br, 2), new Rectangle(box.X + 2, box.Y + 2, box.Width - 4, box.Height - 4)); //绘制中心椭圆
            }
            else
            {
                g.DrawRectangle(new Pen(NoCentral_br, 2), new Rectangle(box.X + 2, box.Y + 2, box.Width - 4, box.Height - 4)); //绘制中心椭圆
            }
            g.DrawRectangle(new Pen(Periphery_br, (float)(1.5)), box);                                                         //绘制外椭圆
        }
Пример #17
0
        /// <summary>
        /// 繪製複選控制元件的圖案
        /// </summary>
        /// <param g="Graphics">封裝一個繪圖的類物件</param>
        /// <param rect="Rectangle">單選圖案的繪製區域</param>
        /// <param Above="bool">斷判鼠標是否在控制元件上方</param>
        private void DrawBox(Graphics g, Rectangle rect, bool Above)
        {
            //設定外框的漸變色
            int opacity = Measurement;

            Periphery_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 2, PeripheryColor), Color.FromArgb(opacity, PeripheryColor), LinearGradientMode.ForwardDiagonal);
            //設定中間框形選中時的漸變色
            opacity    = (int)(.4f * opacity + .5f);
            Central_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 10, CentralColor), Color.FromArgb(opacity, CentralColor), LinearGradientMode.ForwardDiagonal);
            //設定中間框形無操作時的漸變色
            opacity      = (int)(.4f * opacity + .5f);
            NoCentral_br = new LinearGradientBrush(rect, Color.FromArgb(opacity / 10, NoCentralColor), Color.FromArgb(opacity, NoCentralColor), LinearGradientMode.ForwardDiagonal);
            int size = this.Font.Height;//取得字體的高度
            //取得外框的區域
            Rectangle box   = new Rectangle(rect.X + ((rect.Width - size) / 2), rect.Y + ((rect.Height - size) / 2), size - 2, size - 2);
            Rectangle glyph = new Rectangle(box.X + 3, box.Y + 3, box.Width - 6, box.Height - 6);//設定內框的繪製區域
            Rectangle right = new Rectangle(box.X, box.Y - 1, box.Width + 2, box.Height + 2);

            g.FillEllipse(new SolidBrush(SystemColors.Window), box); //以白色填充單選圖案

            if (this.CheckState != CheckState.Unchecked)             //如果是選中狀態
            {
                base.ForeColor = Color.DarkBlue;
                ControlPaint.DrawMenuGlyph(g, right, MenuGlyph.Checkmark, this.StippleColor, Color.White); //繪製對號
                g.DrawRectangle(new Pen(new SolidBrush(SystemColors.Control), (float)(3)), box);           //繪製外框
            }
            if (this.CheckState == CheckState.Indeterminate)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(127, SystemColors.Control)), right);
            }

            if (Above && this.Enabled)                                                                                       //如果鼠標移入該控制元件
            {
                g.DrawRectangle(new Pen(Central_br, 2), new Rectangle(box.X + 2, box.Y + 2, box.Width - 4, box.Height - 4)); //繪製中心框
            }
            else
            {
                g.DrawRectangle(new Pen(NoCentral_br, 2), new Rectangle(box.X + 2, box.Y + 2, box.Width - 4, box.Height - 4)); //繪製中心框
            }
            g.DrawRectangle(new Pen(Periphery_br, (float)(1.5)), box);                                                         //繪製外框
        }
Пример #18
0
        private void DrawGlypth1(Graphics graphics)
        {
            Color foreColor;

            if ((this.RightToLeft != RightToLeft.Yes && this.IsPrevMonthInRange()) ||
                (this.RightToLeft == RightToLeft.Yes && this.IsNextMonthInRange()))
            {
                foreColor = this.titleForeColor;
            }
            else
            {
                // foreColor = SystemColors.GrayText;
                return;
            }
            using (Bitmap image = new Bitmap(GlyphSize.Width, GlyphSize.Height)) {
                using (Graphics grphcs = Graphics.FromImage(image)) {
                    ControlPaint.DrawMenuGlyph(grphcs, 0, 0, GlyphSize.Width, GlyphSize.Height,
                                               MenuGlyph.Arrow, this.titleForeColor, this.titleBackColor);
                }
                image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                graphics.DrawImage(image, this.glyph1Bounds);
            }
        }
Пример #19
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            //draw text-label part of the control with something so that it isn't hallofmirrorsy
            using (var brush = new SolidBrush(Parent.BackColor))
                pevent.Graphics.FillRectangle(brush, ClientRectangle);

            var r        = new Rectangle(ClientRectangle.Location, SystemInformation.MenuCheckSize);
            var glyphLoc = ClientRectangle;

            glyphLoc.Size = SystemInformation.MenuCheckSize;

            //draw the selectedbackdrop color roughly where the glyph belongs
            using (var brush = new SolidBrush(_CheckBackColor))
                pevent.Graphics.FillRectangle(brush, glyphLoc);

            //draw a checkbox menu glyph (we could do this more elegantly with DrawFrameControl)
            bool c = CheckState == CheckState.Checked;

            if (ForceChecked.HasValue)
            {
                c = ForceChecked.Value;
            }
            if (c)
            {
                glyphLoc.Y--;
                glyphLoc.X++;
                ControlPaint.DrawMenuGlyph(pevent.Graphics, glyphLoc, MenuGlyph.Checkmark, Color.Black, Color.Transparent);
            }

            //draw a border on top of it all
            ControlPaint.DrawBorder3D(pevent.Graphics, r, Border3DStyle.Sunken);

            //stuff that didnt work
            //CheckBoxRenderer.DrawParentBackground(pevent.Graphics, ClientRectangle, this);
            //CheckBoxRenderer.DrawCheckBox(pevent.Graphics, ClientRectangle.Location, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
            //glyphLoc.Size = new System.Drawing.Size(SystemInformation.MenuCheckSize.Width-1,SystemInformation.MenuCheckSize.Height-1);
        }
Пример #20
0
        private void MenuItem_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            e.Graphics.InterpolationMode  = InterpolationMode.Low;
            bool isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            if (isSelected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Menu, e.Bounds);
            }
            if (((MenuItem)sender).Text == "-")
            {
                Rectangle bounds = e.Bounds;
                int       top    = bounds.Top;
                bounds = e.Bounds;
                int      num1        = bounds.Height / 2;
                int      num2        = top + num1 - 1;
                Graphics graphics1   = e.Graphics;
                Pen      controlDark = SystemPens.ControlDark;
                bounds = e.Bounds;
                int x1_1 = bounds.Left + 1;
                int y1_1 = num2;
                bounds = e.Bounds;
                int left1 = bounds.Left;
                bounds = e.Bounds;
                int width1 = bounds.Width;
                int x2_1   = left1 + width1 - 2;
                int y2_1   = num2;
                graphics1.DrawLine(controlDark, x1_1, y1_1, x2_1, y2_1);
                Graphics graphics2         = e.Graphics;
                Pen      controlLightLight = SystemPens.ControlLightLight;
                bounds = e.Bounds;
                int x1_2 = bounds.Left + 1;
                int y1_2 = num2 + 1;
                bounds = e.Bounds;
                int left2 = bounds.Left;
                bounds = e.Bounds;
                int width2 = bounds.Width;
                int x2_2   = left2 + width2 - 2;
                int y2_2   = num2 + 1;
                graphics2.DrawLine(controlLightLight, x1_2, y1_2, x2_2, y2_2);
            }
            else
            {
                this.DrawText(sender, e, isSelected);
                if (((MenuItem)sender).Checked)
                {
                    if (((MenuItem)sender).RadioCheck)
                    {
                        Graphics graphics      = e.Graphics;
                        int      x             = e.Bounds.Left + (26 - SystemInformation.MenuCheckSize.Width) / 2;
                        int      top           = e.Bounds.Top;
                        int      height1       = e.Bounds.Height;
                        Size     menuCheckSize = SystemInformation.MenuCheckSize;
                        int      height2       = menuCheckSize.Height;
                        int      num           = (height1 - height2) / 2;
                        int      y             = top + num + 1;
                        menuCheckSize = SystemInformation.MenuCheckSize;
                        int width = menuCheckSize.Width;
                        menuCheckSize = SystemInformation.MenuCheckSize;
                        int   height3   = menuCheckSize.Height;
                        Color foreColor = isSelected ? SystemColors.HighlightText : SystemColors.MenuText;
                        Color backColor = isSelected ? SystemColors.Highlight : SystemColors.Menu;
                        ControlPaint.DrawMenuGlyph(graphics, x, y, width, height3, MenuGlyph.Bullet, foreColor, backColor);
                    }
                    else
                    {
                        Graphics graphics      = e.Graphics;
                        int      x             = e.Bounds.Left + (26 - SystemInformation.MenuCheckSize.Width) / 2;
                        int      top           = e.Bounds.Top;
                        int      height1       = e.Bounds.Height;
                        Size     menuCheckSize = SystemInformation.MenuCheckSize;
                        int      height2       = menuCheckSize.Height;
                        int      num           = (height1 - height2) / 2;
                        int      y             = top + num + 1;
                        menuCheckSize = SystemInformation.MenuCheckSize;
                        int width = menuCheckSize.Width;
                        menuCheckSize = SystemInformation.MenuCheckSize;
                        int   height3   = menuCheckSize.Height;
                        Color foreColor = isSelected ? SystemColors.HighlightText : SystemColors.MenuText;
                        Color backColor = isSelected ? SystemColors.Highlight : SystemColors.Menu;
                        ControlPaint.DrawMenuGlyph(graphics, x, y, width, height3, MenuGlyph.Checkmark, foreColor, backColor);
                    }
                }
                else
                {
                    Image image = this.GetImage((MenuItem)sender);
                    if (image != null)
                    {
                        if (((MenuItem)sender).Enabled)
                        {
                            e.Graphics.DrawImage(image, e.Bounds.Left + 4, e.Bounds.Top + (e.Bounds.Height - 16) / 2, 16, 16);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, image, e.Bounds.Left + 4, e.Bounds.Top + (e.Bounds.Height - 16) / 2, SystemColors.Menu);
                        }
                    }
                }
            }
        }
Пример #21
0
        void MenuItem_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.Graphics.CompositingQuality = CompositingQuality.HighSpeed;
            e.Graphics.InterpolationMode  = InterpolationMode.Low;

            bool menuSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            if (menuSelected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Menu, e.Bounds);
            }

            if (((MenuItem)sender).Text == "-")
            {
                //draw the separator
                int yCenter = e.Bounds.Top + (e.Bounds.Height / 2) - 1;

                e.Graphics.DrawLine(SystemPens.ControlDark, e.Bounds.Left + 1, yCenter, (e.Bounds.Left + e.Bounds.Width - 2), yCenter);
                e.Graphics.DrawLine(SystemPens.ControlLightLight, e.Bounds.Left + 1, yCenter + 1, (e.Bounds.Left + e.Bounds.Width - 2), yCenter + 1);
            }
            else //regular menu items
            {
                //draw the item text
                DrawText(sender, e, menuSelected);

                if (((MenuItem)sender).Checked)
                {
                    if (((MenuItem)sender).RadioCheck)
                    {
                        //draw the bullet
                        ControlPaint.DrawMenuGlyph(e.Graphics,
                                                   e.Bounds.Left + (LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN - SystemInformation.MenuCheckSize.Width) / 2,
                                                   e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuCheckSize.Height) / 2 + 1,
                                                   SystemInformation.MenuCheckSize.Width,
                                                   SystemInformation.MenuCheckSize.Height,
                                                   MenuGlyph.Bullet,
                                                   menuSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                                   menuSelected ? SystemColors.Highlight : SystemColors.Menu);
                    }
                    else
                    {
                        //draw the check mark
                        ControlPaint.DrawMenuGlyph(e.Graphics,
                                                   e.Bounds.Left + (LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN - SystemInformation.MenuCheckSize.Width) / 2,
                                                   e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuCheckSize.Height) / 2 + 1,
                                                   SystemInformation.MenuCheckSize.Width,
                                                   SystemInformation.MenuCheckSize.Height,
                                                   MenuGlyph.Checkmark,
                                                   menuSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                                   menuSelected ? SystemColors.Highlight : SystemColors.Menu);
                    }
                }
                else
                {
                    Image drawImg = EnsurePropertiesExists((MenuItem)sender).PreVistaBitmap;

                    if (drawImg != null)
                    {
                        //draw the image
                        if (((MenuItem)sender).Enabled)
                        {
                            e.Graphics.DrawImage(drawImg, e.Bounds.Left + LEFT_MARGIN,
                                                 e.Bounds.Top + ((e.Bounds.Height - ICON_SIZE) / 2),
                                                 ICON_SIZE, ICON_SIZE);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, drawImg,
                                                           e.Bounds.Left + LEFT_MARGIN,
                                                           e.Bounds.Top + ((e.Bounds.Height - ICON_SIZE) / 2),
                                                           SystemColors.Menu);
                        }
                    }
                }
            }
        }
Пример #22
0
        void MenuItem_DrawItem(object sender, DrawItemEventArgs e)
        {
            //MenuItem menuItem = (MenuItem)sender;
            //MenuHelper menuHelper = new MenuHelper(menuItem, e.Graphics, this);
            bool menuSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            if (menuSelected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Menu, e.Bounds);
            }

            if (((MenuItem)sender).Text == "-")
            {
                //draw the separator
                int yCenter = e.Bounds.Top + (e.Bounds.Height / 2);

                e.Graphics.DrawLine(SystemPens.ControlDark, e.Bounds.Left, yCenter, (e.Bounds.Left + e.Bounds.Width), yCenter);
            }
            else //regular menu items
            {
                //draw the item text
                DrawText(sender, e, menuSelected);

                if (((MenuItem)sender).Checked)
                {
                    if (((MenuItem)sender).RadioCheck)
                    {
                        //draw the bullet
                        ControlPaint.DrawMenuGlyph(e.Graphics,
                                                   e.Bounds.Left + (LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN - SystemInformation.MenuCheckSize.Width) / 2,
                                                   e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuCheckSize.Height) / 2 + 1,
                                                   SystemInformation.MenuCheckSize.Width,
                                                   SystemInformation.MenuCheckSize.Height,
                                                   MenuGlyph.Bullet,
                                                   menuSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                                   menuSelected ? SystemColors.Highlight : SystemColors.Menu);
                    }
                    else
                    {
                        //draw the check mark
                        ControlPaint.DrawMenuGlyph(e.Graphics,
                                                   e.Bounds.Left + (LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN - SystemInformation.MenuCheckSize.Width) / 2,
                                                   e.Bounds.Top + (e.Bounds.Height - SystemInformation.MenuCheckSize.Height) / 2 + 1,
                                                   SystemInformation.MenuCheckSize.Width,
                                                   SystemInformation.MenuCheckSize.Height,
                                                   MenuGlyph.Checkmark,
                                                   menuSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                                   menuSelected ? SystemColors.Highlight : SystemColors.Menu);
                    }
                }
                else
                {
                    Image drawImg = GetImage(((MenuItem)sender));

                    if (drawImg != null)
                    {
                        //draw the image
                        if (((MenuItem)sender).Enabled)
                        {
                            e.Graphics.DrawImage(drawImg, e.Bounds.Left + LEFT_MARGIN,
                                                 e.Bounds.Top + ((e.Bounds.Height - ICON_SIZE) / 2),
                                                 ICON_SIZE, ICON_SIZE);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, drawImg,
                                                           e.Bounds.Left + LEFT_MARGIN,
                                                           e.Bounds.Top + ((e.Bounds.Height - ICON_SIZE) / 2),
                                                           SystemColors.Menu);
                        }
                    }
                }
            }
        }
Пример #23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color colorMenuHighLight = ControlPaint.LightLight(SystemColors.MenuHighlight);

            #region 定义

            //显示图像的位置X坐标
            int imageLocationX = 4;

            //显示图像的位置Y坐标
            int imageLocationY = 2;

            //显示文本的位置X坐标
            int textLocationX = 6;

            //显示文本的位置Y坐标
            //int textLocationY = 4;
            int textLocationY = (int)Math.Round((float)(this.ContentRectangle.Height - (int)Math.Round(this.Font.SizeInPoints)) / 2);

            //子菜单显示文本位置X坐标
            int textLocationX_DropDown = 33;

            //子菜单显示图像的位置X坐标
            int imageLocationX_DropDown = 5;

            //子菜单显示图像的位置Y坐标
            int imageLocationY_DropDown = 3;

            //文本填充
            SolidBrush textBrush = new SolidBrush(this.ForeColor);

            //显示图像的Rectangle
            Rectangle imageRect = new Rectangle(imageLocationX, imageLocationY, 16, 16);

            //子菜单显示图像的Rectangle
            Rectangle imageRect_DropDown = new Rectangle(imageLocationX_DropDown, imageLocationY_DropDown, 16, 16);

            //菜单背景填充
            SolidBrush backBrush_Normal = new SolidBrush(SystemColors.ControlLightLight);

            //菜单背景填充 选中状态
            //LinearGradientBrush backBrush_Selected = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height),
            //            Color.FromArgb(255, 246, 204), Color.FromArgb(255, 194, 115));
            LinearGradientBrush backBrush_Selected = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height),
                                                                             Color.White, colorMenuHighLight);


            //菜单背景填充 按下状态
            //LinearGradientBrush backBrush_Pressed = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height),
            //            Color.White, Color.LightSkyBlue);
            LinearGradientBrush backBrush_Pressed = new LinearGradientBrush(new Point(0, 0), new Point(0, this.Height),
                                                                            Color.White, colorMenuHighLight);

            //子菜单左侧边条的填充
            LinearGradientBrush leftBrush_DropDown = new LinearGradientBrush(new Point(0, 0), new Point(25, 0),
                                                                             Color.White, Color.FromArgb(233, 230, 215));

            //填充Rectangle 顶层
            Rectangle fillRect = new Rectangle(0, 0, this.Bounds.Width, this.Bounds.Height);

            //子菜单填充Rectangle
            Rectangle fillRect_DropDown = new Rectangle(2, 0, this.Bounds.Width - 4, this.Bounds.Height);

            //边框Rectangle 顶层
            Rectangle drawRect = new Rectangle(0, 0, this.Bounds.Width - 1, this.Bounds.Height - 1);

            //子菜单边框Rectangle
            Rectangle drawRect_DropDown = new Rectangle(3, 0, this.Bounds.Width - 6, this.Bounds.Height - 2);

            //子菜单左侧与内容的分隔条
            Pen leftLine = new Pen(Color.FromArgb(197, 194, 184));

            //边框画笔 顶层
            //Pen drawPen = new Pen(Color.FromArgb(255, 192, 111));
            Pen drawPen = new Pen(SystemColors.GradientActiveCaption);

            //按下时的边框画笔 顶层
            //Pen drawPen_Pressed = new Pen(Color.SkyBlue);
            Pen drawPen_Pressed = new Pen(SystemColors.GradientActiveCaption);

            //边框画笔
            //Pen drawPen_DropDown = new Pen(Color.FromArgb(255, 192, 111));
            Pen drawPen_DropDown = new Pen(SystemColors.GradientActiveCaption);

            #endregion

            #region 如果不可用,把文本填充色改成灰色,图片灰掉

            //如果不可用,把文本填充色改成灰色
            if (this.Enabled)
            {
                textBrush.Color = this.ForeColor;
            }
            else
            {
                textBrush.Color = Color.LightGray;
            }

            #endregion

            #region 顶层菜单

            //如果是顶层菜单
            if (!this.IsOnDropDown)
            {
                //如果是按下状态
                if (this.Pressed)
                {
                    e.Graphics.FillRectangle(backBrush_Pressed, fillRect);
                    e.Graphics.DrawRectangle(drawPen_Pressed, drawRect);
                }
                //如果是选中状态
                else if (this.Selected)
                {
                    e.Graphics.FillRectangle(backBrush_Selected, fillRect);
                    e.Graphics.DrawRectangle(drawPen, drawRect);
                }

                //绘制图像和文本
                if (this.Image != null)
                {
                    if (this.DisplayStyle == ToolStripItemDisplayStyle.ImageAndText)
                    {
                        if (this.Enabled)
                        {
                            e.Graphics.DrawImage(this.Image, imageRect);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, this.Image, imageRect.X, imageRect.Y, this.BackColor);
                        }

                        e.Graphics.DrawString(this.Text, this.Font, textBrush, new Point(textLocationX + 14, textLocationY), stringFormat);
                    }
                    else if (this.DisplayStyle == ToolStripItemDisplayStyle.Image)
                    {
                        if (this.Enabled)
                        {
                            e.Graphics.DrawImage(this.Image, imageRect);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, this.Image, imageRect.X, imageRect.Y, this.BackColor);
                        }
                    }
                    else if (this.DisplayStyle == ToolStripItemDisplayStyle.Text)
                    {
                        e.Graphics.DrawString(this.Text, this.Font, textBrush, new Point(textLocationX, textLocationY), stringFormat);
                    }
                }
                else
                {
                    e.Graphics.DrawString(this.Text, this.Font, textBrush, new Point(textLocationX, textLocationY), stringFormat);
                }
            }

            #endregion

            #region 如果不是顶层菜单

            //如果不是顶层菜单
            else
            {
                #region 如果是选中或是按下状态

                //如果是选中或是按下状态
                if (this.Selected || this.Pressed)
                {
                    //e.Graphics.FillRectangle(backBrush_Selected,fillRect_DropDown);

                    e.Graphics.FillRectangle(backBrush_Normal, fillRect_DropDown);
                    e.Graphics.FillRectangle(leftBrush_DropDown, 0, 0, 25, this.Height);
                    e.Graphics.DrawLine(leftLine, 25, 0, 25, this.Height);

                    //如果可用
                    if (this.Enabled)
                    {
                        //GraphPlotting.FillRoundRect(e.Graphics, backBrush_Selected, drawRect_DropDown, 0, 2);
                        //GraphPlotting.DrawRoundRect(e.Graphics, drawPen_DropDown, drawRect_DropDown, 2);

                        e.Graphics.FillPath(backBrush_Selected, DrawingTool.RoundedRect(drawRect_DropDown, 3));
                        e.Graphics.DrawPath(drawPen_DropDown, DrawingTool.RoundedRect(drawRect_DropDown, 3));
                    }

                    if (this.Image != null)
                    {
                        //子菜单这里可以写在一起
                        //因为不管有没有图,文本的位置是不变的
                        if (this.DisplayStyle == ToolStripItemDisplayStyle.ImageAndText ||
                            this.DisplayStyle == ToolStripItemDisplayStyle.Image
                            )
                        {
                            if (this.Enabled)
                            {
                                e.Graphics.DrawImage(this.Image, imageRect_DropDown);
                            }
                            else
                            {
                                ControlPaint.DrawImageDisabled(e.Graphics, this.Image, imageRect_DropDown.X, imageRect_DropDown.Y, this.BackColor);
                            }
                        }
                    }

                    e.Graphics.DrawString(this.Text, this.Font, textBrush, new Point(textLocationX_DropDown, textLocationY), stringFormat);
                }

                #endregion

                #region 如果未选中也未按下

                //如果未选中也未按下
                else
                {
                    e.Graphics.FillRectangle(backBrush_Normal, fillRect_DropDown);
                    e.Graphics.FillRectangle(leftBrush_DropDown, 0, 0, 25, this.Height);
                    e.Graphics.DrawLine(leftLine, 25, 0, 25, this.Height);

                    if (this.Image != null)
                    {
                        if (this.DisplayStyle == ToolStripItemDisplayStyle.ImageAndText ||
                            this.DisplayStyle == ToolStripItemDisplayStyle.Image)
                        {
                            if (this.Enabled)
                            {
                                e.Graphics.DrawImage(this.Image, imageRect_DropDown);
                            }
                            else
                            {
                                ControlPaint.DrawImageDisabled(e.Graphics, this.Image, imageRect_DropDown.X, imageRect_DropDown.Y, this.BackColor);
                            }
                        }
                    }

                    e.Graphics.DrawString(this.Text, this.Font, textBrush, new Point(textLocationX_DropDown, textLocationY), stringFormat);
                }

                #endregion

                #region 处理Checked = true

                //       ControlPaint.draw
                //   MenuGlyph.

                if (this.Checked)
                {
                    ControlPaint.DrawMenuGlyph
                        (e.Graphics, imageLocationX_DropDown, imageLocationY_DropDown, 16, 16,
                        MenuGlyph.Checkmark, Color.Black, SystemColors.GradientActiveCaption);
                }

                #endregion

                #region 如果还有子菜单,画向右箭头

                if (this.DropDownItems.Count > 0)
                {
                    ControlPaint.DrawMenuGlyph
                        (e.Graphics, this.Width - 20, imageLocationY_DropDown, 16, 16,
                        MenuGlyph.Arrow, Color.Black, Color.Transparent);
                }

                #endregion
            }

            #endregion


            #region 释放资源

            //释放资源
            textBrush.Dispose();
            backBrush_Normal.Dispose();
            backBrush_Selected.Dispose();
            backBrush_Pressed.Dispose();
            leftBrush_DropDown.Dispose();
            leftLine.Dispose();
            drawPen.Dispose();
            drawPen_Pressed.Dispose();
            drawPen_DropDown.Dispose();

            #endregion
        }
Пример #24
0
        protected virtual void DrawMenuItems(Graphics g)
        {
            // The text doesn't wrap but instead disappears under the right edge of the menu item rectangle.
            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);

            sf.Alignment     = this.selector.Alignment; // Horizontal Alignment
            sf.LineAlignment = StringAlignment.Center;  // Vertical Alignment

            for (int i = 0; i < items.Count; i++)
            {
                MenuItem  currentItem = items[i];
                Rectangle rct         = currentItem.ItemRectangle;

                // Object Initializer
                Rectangle textRct = new Rectangle()
                {
                    X      = barGradientWidth + 5,
                    Y      = rct.Y,
                    Width  = this.Width - (barGradientWidth + 4),
                    Height = rct.Height
                };

                if (i == hotIndex)
                {
                    using (Pen pen = new Pen(this.selector.MenuItem.ItemBorderColor))
                    {
                        g.DrawRectangle(pen, rct.X, rct.Y, rct.Width - 1, rct.Height - 1);
                    }

                    rct.Inflate(-1, -1);
                    using (LinearGradientBrush brush = new LinearGradientBrush(rct, this.selector.MenuItem.ColorStart,
                                                                               this.selector.MenuItem.ColorEnd, this.selector.MenuItem.GradientStyle))
                    {
                        g.FillRectangle(brush, rct);
                    }

                    // Draw Checkbox border and gradient area if current menu item is checked.
                    if (currentItem.IsChecked)
                    {
                        rct.Inflate(-1, -1);
                        rct.Width = barGradientWidth - 8;
                        using (Pen pen = new Pen(this.selector.HoverAreaCheckBox.BorderColor))
                        {
                            g.DrawRectangle(pen, rct.X, rct.Y, rct.Width - 1, rct.Height - 1);
                        }

                        rct.Inflate(-1, -1);
                        using (LinearGradientBrush brush = new LinearGradientBrush(rct, this.selector.HoverAreaCheckBox.ColorStart,
                                                                                   this.selector.HoverAreaCheckBox.ColorEnd, this.selector.HoverAreaCheckBox.GradientStyle))
                        {
                            g.FillRectangle(brush, rct);
                            rct.Inflate(1, 1);
                            rct.X += 1;
                            ControlPaint.DrawMenuGlyph(g, rct, MenuGlyph.Checkmark, this.selector.HoverAreaCheckBox.TickColor, Color.Transparent);
                        }
                    }

                    // Draw MenuItem Text.
                    using (SolidBrush brush = new SolidBrush(this.selector.MenuItem.ItemHoverForeColor))
                    {
                        g.DrawString(currentItem.ItemText, this.Font, brush, textRct, sf);
                    }
                }
                else
                {
                    // Draw Checkbox border and gradient area if current menu item is checked.
                    if (currentItem.IsChecked)
                    {
                        rct.Inflate(-2, -2);
                        rct.Width = barGradientWidth - 8;
                        using (Pen pen = new Pen(this.selector.AreaCheckBox.BorderColor))
                        {
                            g.DrawRectangle(pen, rct.X, rct.Y, rct.Width - 1, rct.Height - 1);
                        }

                        rct.Inflate(-1, -1);
                        using (LinearGradientBrush brush = new LinearGradientBrush(rct, this.selector.AreaCheckBox.ColorStart,
                                                                                   this.selector.AreaCheckBox.ColorEnd, this.selector.AreaCheckBox.GradientStyle))
                        {
                            g.FillRectangle(brush, rct);
                            rct.Inflate(1, 1);
                            rct.X += 1;
                            ControlPaint.DrawMenuGlyph(g, rct, MenuGlyph.Checkmark, this.selector.AreaCheckBox.TickColor, Color.Transparent);
                        }
                    }

                    // Draw MenuItem Text.
                    using (SolidBrush brush = new SolidBrush(this.selector.MenuItem.ItemForeColor))
                    {
                        g.DrawString(currentItem.ItemText, this.Font, brush, textRct, sf);
                    }
                }
            }

            // Draw exit button border, fill and it's string.
            CustomDataGridViewKRBColumnSelector.DataGridViewKRBColumnSelector.ButtonExit exitButton = this.selector.ExitButton;
            Rectangle exitRct = exitRectangle;

            ControlPaint.DrawBorder3D(g, exitRct, exitButton.ButtonBorderStyle, Border3DSide.All);
            Size size3d = SystemInformation.Border3DSize;

            exitRct.Inflate(-size3d.Width, -size3d.Height);
            using (SolidBrush brush = new SolidBrush(hotIndex == -1 ? exitButton.HoverBackColor : exitButton.BackColor))
            {
                g.FillRectangle(brush, exitRct);
                brush.Color = hotIndex == -1 ? exitButton.HoverForeColor : exitButton.ForeColor;
                //g.DrawString("Exit", this.Font, brush, exitRct, sf);
                g.DrawString("退出", this.Font, brush, exitRct, sf);
            }
        }
Пример #25
0
        public static void PopupMenu_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e, bool withArrows)
        {
            PopupMenuItem item    = (PopupMenuItem)sender;
            string        caption = item.Text;

            //Paint background
            Color      backColor = item.BackColor;
            SolidBrush brush     = new SolidBrush(Settings.MenuItemBackColor);

            e.Graphics.FillRectangle(brush, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);


            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                brush.Color = Settings.MenuItemSelectedBackColor;
                e.Graphics.FillRectangle(brush, e.Bounds.Left + 1, e.Bounds.Top + 3, e.Bounds.Width - 1, e.Bounds.Height - 6);
            }

            //Draw text
            if (item.Text != "-")
            {
                int horizOffset = 16;
                if (item.Enabled)
                {
                    if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                    {
                        brush.Color = Settings.MenuItemSelectedForeColor;
                    }
                    else
                    {
                        brush.Color = Settings.MenuItemForeColor;
                    }
                }
                else
                {
                    brush.Color = Settings.MenuItemDisabledForeColor;
                }

                StringFormat sf = new StringFormat();
                sf.HotkeyPrefix  = HotkeyPrefix.Hide;
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Center;
                Rectangle textRect = new Rectangle(
                    e.Bounds.Left + horizOffset, e.Bounds.Top,
                    e.Bounds.Width - horizOffset, e.Bounds.Height);
                e.Graphics.DrawString(caption, e.Font, brush, textRect, sf);

                if (item.Image != null)
                {
                    //e.Graphics.DrawImageUnscaled(item.Image, e.Bounds.Location.X, e.Bounds.Location.Y);
                    e.Graphics.DrawImage(item.Image, e.Bounds.Location.X, e.Bounds.Location.Y + 1, item.Image.Width, item.Image.Height);
                    //item.Image.Save("c:\\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                }
            }
            else
            {
                //Draw separator line
                Pen   pen = new Pen(Color.White, 1);
                Point src = new Point(e.Bounds.Left, e.Bounds.Top + 1);
                Point dst = new Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top + 1);
                e.Graphics.DrawLine(pen, src, dst);
                pen.Dispose();
            }
            //Draw check mark
            if ((e.State & DrawItemState.Checked) == DrawItemState.Checked)
            {
                Size     arrSize = new Size(e.Bounds.Height - 4, e.Bounds.Height - 4);
                Bitmap   bitmap  = new Bitmap(arrSize.Height, arrSize.Height);
                Graphics g       = Graphics.FromImage(bitmap);
                g.Clear(Color.Transparent);
                ControlPaint.DrawMenuGlyph(g, new Rectangle(0, 1, arrSize.Width, arrSize.Height), MenuGlyph.Checkmark);
                bitmap.MakeTransparent();
                DrawMenyGlypth(e.Graphics, bitmap, new Rectangle(0, 0, arrSize.Width, arrSize.Height), new Rectangle(e.Bounds.Left + 2, // srcX
                                                                                                                     e.Bounds.Top + 1,  // srcY
                                                                                                                     arrSize.Width,
                                                                                                                     arrSize.Height), (e.State & DrawItemState.Selected) == DrawItemState.Selected);
            }
            //Draw arrow
            if (item.IsParent && withArrows)
            {
                Size     arrSize = new Size(e.Bounds.Height - 2, e.Bounds.Height - 2);
                Bitmap   bitmap  = new Bitmap(arrSize.Height, arrSize.Height);
                Graphics g       = Graphics.FromImage(bitmap);
                g.Clear(Color.Transparent);
                ControlPaint.DrawMenuGlyph(g, new Rectangle(0, 1, arrSize.Width, arrSize.Height), MenuGlyph.Arrow);
                bitmap.MakeTransparent();
                DrawMenyGlypth(e.Graphics, bitmap, new Rectangle(0, 0, arrSize.Width, arrSize.Height), new Rectangle(e.Bounds.Left + (e.Bounds.Width - e.Bounds.Height), // srcX
                                                                                                                     e.Bounds.Top + 1,                                   // srcY
                                                                                                                     arrSize.Width,
                                                                                                                     arrSize.Height), (e.State & DrawItemState.Selected) == DrawItemState.Selected);
            }

            brush.Dispose();
        }
Пример #26
0
        private void DrawIcon(Graphics gfx, Rectangle rect,
                              bool isSelected, bool isChecked, bool isRadioChecked, bool isEnabled)
        {
            System.Windows.Forms.ImageList iconImageList = null;

            IconMainMenu m = (IconMainMenu)this.GetMainMenu();

            if (m != null)
            {
                iconImageList = m.IconImageList;
            }
            else
            {
                IconContextMenu c = (IconContextMenu)this.GetContextMenu();
                if (c != null)
                {
                    iconImageList = c.IconImageList;
                }
            }

            bool hasIcon = false;

            if (iconImageList != null)
            {
                if ((m_iconIndex >= 0) && (m_iconIndex < iconImageList.Images.Count))
                {
                    hasIcon = true;

                    int x = rect.Left + (iconWidth - iconImageList.ImageSize.Width) / 2;
                    int y = rect.Top + (rect.Height - iconImageList.ImageSize.Height) / 2;

                    if ((isSelected) && (isEnabled))
                    {
                        // draw icon as a shadow here
                        ControlPaint.DrawImageDisabled(gfx,
                                                       iconImageList.Images[m_iconIndex],
                                                       x, y, Color.FromKnownColor(KnownColor.Control));
                        x -= 1;
                        y -= 1;
                    }
                    if (isEnabled)
                    {
                        iconImageList.Draw(gfx, x, y,
                                           iconImageList.ImageSize.Width, iconImageList.ImageSize.Height, m_iconIndex);
                    }
                    else
                    {
                        ControlPaint.DrawImageDisabled(gfx,
                                                       iconImageList.Images[m_iconIndex],
                                                       x, y, Color.FromKnownColor(KnownColor.Control));
                    }
                }
            }

            if (isChecked)
            {
                Rectangle checkRect = rect;
                checkRect.Width = iconWidth;
                checkRect.Inflate(-1, -1);
                checkRect.Height -= 1;
                Pen pen = SystemPens.Highlight;
                gfx.DrawRectangle(pen, checkRect);
                if (!hasIcon)
                {
                    int x = rect.Left + (iconWidth - SystemInformation.MenuCheckSize.Width) / 2;
                    int y = rect.Top + (rect.Height - SystemInformation.MenuCheckSize.Width) / 2;

                    // Fill the background of the check item with an alpha-blended
                    // highlight colour:
                    int alpha = 24;
                    if (isSelected)
                    {
                        alpha = 128;
                    }
                    Brush br = new SolidBrush(Color.FromArgb(alpha, Color.FromKnownColor(KnownColor.Highlight)));
                    gfx.FillRectangle(br, checkRect);
                    br.Dispose();

                    // create a new bitmap to draw the menu glyph onto:
                    Bitmap   bm = new Bitmap(SystemInformation.MenuCheckSize.Width, SystemInformation.MenuCheckSize.Height);
                    Graphics gr = Graphics.FromImage(bm);
                    if (isRadioChecked)
                    {
                        // draw radio option
                        ControlPaint.DrawMenuGlyph(gr, 0, 0,
                                                   bm.Width, bm.Height,
                                                   MenuGlyph.Bullet);
                    }
                    else
                    {
                        // draw check mark
                        ControlPaint.DrawMenuGlyph(gr, 0, 0,
                                                   bm.Width, bm.Height,
                                                   MenuGlyph.Checkmark);
                    }
                    Rectangle outRect = new Rectangle(x, y, bm.Width, bm.Height);
                    // Draw the menu glyph transparently:
                    ImageAttributes imgAttr = new ImageAttributes();
                    imgAttr.SetColorKey(bm.GetPixel(0, 0), bm.GetPixel(0, 0), ColorAdjustType.Default);
                    gfx.DrawImage(bm, outRect, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, imgAttr);
                    imgAttr.Dispose();
                    bm.Dispose();
                    gr.Dispose();
                }
            }
        }