예제 #1
0
        public override void OnPaint(CellDrawingContext dc)
        {
            var g = dc.Graphics;

            RGFloat hh = Bounds.Height / 2 - 1;

            Rectangle rect = Bounds;

            Rectangle upRect = new Rectangle(rect.Right - ButtonSize, rect.Top, ButtonSize, hh);

            GraphicsToolkit.Draw3DButton(g.PlatformGraphics, (System.Drawing.Rectangle)upRect, isUpPressed);
            GraphicsToolkit.FillTriangle(g.PlatformGraphics, ArrowSize,
                                         new Point(upRect.Left + ButtonSize / 2 - ArrowSize / 2,
                                                   upRect.Top + hh / 2 + (isUpPressed ? 2 : 1)),
                                         GraphicsToolkit.TriangleDirection.Up);

            Rectangle downRect = new Rectangle(rect.Right - ButtonSize, rect.Top + hh + 1, ButtonSize, hh);

            GraphicsToolkit.Draw3DButton(g.PlatformGraphics, (System.Drawing.Rectangle)downRect, isDownPressed);
            GraphicsToolkit.FillTriangle(g.PlatformGraphics, ArrowSize,
                                         new Point(downRect.Left + ButtonSize / 2 - ArrowSize / 2,
                                                   downRect.Top + hh / 2 - (isDownPressed ? 1 : 2)),
                                         GraphicsToolkit.TriangleDirection.Down);
        }
예제 #2
0
        /// <summary>
        /// Override OnPaint method
        /// </summary>
        /// <param name="e">paint event argument</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;

            int hh = (int)Math.Round(Height / 2f);

            GraphicsToolkit.FillTriangle(g, 8, new Point(10, hh), GraphicsToolkit.TriangleDirection.Left,
                                         viewScroll > 0 ? SystemPens.WindowText : SystemPens.GrayText);

            int max = this.maxWidth - this.ClientRectangle.Width + rightPadding + 10;

            GraphicsToolkit.FillTriangle(g, 8, new Point(20, hh), GraphicsToolkit.TriangleDirection.Right,
                                         viewScroll < max ? SystemPens.WindowText : SystemPens.GrayText);

            var controlStyle = this.grid.ControlStyle;

            var borderPen        = this.resourceManager.GetPen(controlStyle[ControlAppearanceColors.SheetTabBorder]);
            var defaultTextBrush = this.resourceManager.GetBrush(this.ForeColor);

            Rectangle rect = new Rectangle(leftPadding, 0, ClientRectangle.Width - 4, ClientRectangle.Height - 2);

            #region Border
            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
            {
                switch (this.Position)
                {
                default:
                case SheetTabControlPosition.Top:
                    g.DrawLine(borderPen, 0, rect.Bottom - 1,
                               ClientRectangle.Right, rect.Bottom - 1);
                    break;

                case SheetTabControlPosition.Bottom:
                    g.DrawLine(borderPen, 0, rect.Top, ClientRectangle.Right, rect.Top);
                    break;
                }
            }
            #endregion

            g.SetClip(new Rectangle(ClientRectangle.Left + leftPadding, ClientRectangle.Top,
                                    ClientRectangle.Width - leftPadding - rightPadding, ClientRectangle.Height));

            g.TranslateTransform(-this.viewScroll, 0);

            using (var sf = new StringFormat(StringFormat.GenericTypographic)
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
            })
            {
                int textTopPadding = (this.ClientRectangle.Height - this.Font.Height) / 2;

                #region Unselected items

                for (int i = 0; i < tabs.Count; i++)
                {
                    var tab = this.tabs[i];
                    rect = tab.Bounds;

                    if (i != selectedIndex)
                    {
                        if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                        {
                            using (var bb = new SolidBrush(tab.BackgroundColor))
                            {
                                g.FillRectangle(bb, rect);
                            }
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, defaultTextBrush, rect, sf);
                        }

                        if (i > 0)
                        {
                            g.DrawLine(SystemPens.ControlDark, rect.Left, rect.Top + 4, rect.Left, rect.Bottom - 4);
                        }
                    }

                    if (rect.Left > maxWidth)
                    {
                        break;
                    }
                }

                #endregion

                #region Selected item

                if (this.selectedIndex >= 0 && this.selectedIndex < this.tabs.Count)
                {
                    var tab = this.tabs[this.selectedIndex];
                    rect = tab.Bounds;

                    if (rect.Right > this.viewScroll ||
                        rect.Left < this.maxWidth - this.viewScroll)
                    {
                        int x = rect.Left, x2 = rect.Right, y = 0, y2 = 0;

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                        {
                            if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                            {
                                x++; x2--;
                            }

                            switch (this.Position)
                            {
                            default:
                            case SheetTabControlPosition.Top:
                                y = rect.Top; y2 = rect.Bottom;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y++; y2--;
                                }

                                break;

                            case SheetTabControlPosition.Bottom:
                                y = rect.Bottom - 1; y2 = rect.Top;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y--; y2++;
                                }

                                break;
                            }

                            // left and right
                            g.DrawLine(borderPen, rect.Left, y, rect.Left, y2);
                            g.DrawLine(borderPen, rect.Right, y, rect.Right, y2);
                        }

                        Brush selectedBackBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabSelected]);
                        Brush selectedTextBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabText]);

                        // top or bottom
                        switch (this.Position)
                        {
                        default:
                        case SheetTabControlPosition.Top:
                            var bgrectTop = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectTop);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectTop);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Top, x2, rect.Top);
                            }
                            break;

                        case SheetTabControlPosition.Bottom:

                            var bgrectBottom = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectBottom);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectBottom);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Bottom - 1, x2, rect.Bottom - 1);
                            }
                            break;
                        }

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder && Shadow)
                        {
                            g.DrawLine(borderPen, rect.Right + 1, rect.Top + 2, rect.Right + 1, rect.Bottom - 1);
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, selectedTextBrush, rect, sf);
                        }
                    }
                }

                #endregion                 // Selected item
            }

            g.ResetClip();
            g.ResetTransform();

            if (this.NewButtonVisible)
            {
                g.DrawImage(addButtonHover ? newButtonImage : newButtonDisableImage,
                            new Rectangle(this.ClientRectangle.Width - 28, (this.ClientRectangle.Height - 16) / 2, 16, 16));
            }

            for (int i = 4; i < this.ClientRectangle.Height - 4; i += 4)
            {
                g.FillRectangle(SystemBrushes.ControlDark, new Rectangle(this.ClientRectangle.Right - 5, i, 2, 2));
            }

            if (this.movingHoverIndex >= 0 && this.movingHoverIndex <= this.tabs.Count &&
                this.movingHoverIndex != this.movingStartIndex)
            {
                Rectangle itemRect = GetItemBounds(this.movingHoverIndex >= this.tabs.Count ?
                                                   this.tabs.Count - 1 : this.movingHoverIndex);

                GraphicsToolkit.FillTriangle(g, 8, new Point(
                                                 (this.movingHoverIndex >= this.tabs.Count ? itemRect.Right : itemRect.Left) - this.viewScroll,
                                                 itemRect.Top + 4), GraphicsToolkit.TriangleDirection.Up);
            }

            base.OnPaint(e);
        }
예제 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g     = e.Graphics;
            int      index = -1;

            using (SolidBrush b = new SolidBrush(Color.White))
            {
                for (int x = 8, i = 0; x < 160 && i < fixedColor.Length; i++, x += 20)
                {
                    for (int y = 8, p = 0; y < 100; p++, y += 20)
                    {
                        index++;

                        if (index == hoverColorIndex)
                        {
                            b.Color = SystemColors.Highlight;
                            g.FillRectangle(b, x - 2, y - 2, 18, 18);
                            g.DrawRectangle(SystemPens.WindowFrame, x - 2, y - 2, 18, 18);
                        }

                        if (index == selectedColorIndex)
                        {
                            g.DrawRectangle(SystemPens.Highlight, x - 2, y - 2, 18, 18);
                        }

                        b.Color = fixedColor[i, p];

                        g.DrawRectangle(Pens.Black, x, y, 14, 14);
                        g.FillRectangle(b, x + 1, y + 1, 13, 13);
                    }
                }

                g.DrawLine(SystemPens.ControlDark, 4, 110, ClientRectangle.Width - 4, 110);

                // no color
                index++;

                if (index == hoverColorIndex)
                {
                    b.Color = SystemColors.Highlight;
                    g.FillRectangle(b, 6, 113, 80, 21);
                    g.DrawRectangle(SystemPens.WindowFrame, 6, 113, 80, 21);
                }

                if (index == selectedColorIndex)
                {
                    g.DrawRectangle(SystemPens.Highlight, 6, 113, 80, 21);
                }

                g.DrawRectangle(Pens.Black, 8, 116, 14, 14);
                g.DrawLine(Pens.Black, 8, 130, 22, 116);
                g.DrawString(ReoGrid.Editor.LangRes.LangResource.NoColor, Font,
                             index == hoverColorIndex ?
                             SystemBrushes.HighlightText : SystemBrushes.WindowText,
                             new Rectangle(26, 116, 60, 20));

                // more
                index++;

                if (index == hoverColorIndex)
                {
                    b.Color = SystemColors.Highlight;
                    g.FillRectangle(b, 95, 113, 68, 21);
                    g.DrawRectangle(SystemPens.WindowFrame, 95, 113, 68, 21);
                }

                if (index == selectedColorIndex)
                {
                    g.DrawRectangle(SystemPens.Highlight, 95, 113, 68, 21);
                }

                g.DrawLine(SystemPens.ControlDark, 90, 115, 90, 132);

                b.Color = currentColor;
                g.FillRectangle(b, 100, 116, 14, 14);

                g.DrawRectangle(Pens.Black, 100, 116, 14, 14);
                g.DrawString(ReoGrid.Editor.LangRes.LangResource.Menu_More, Font,
                             index == hoverColorIndex ?
                             SystemBrushes.HighlightText : SystemBrushes.WindowText,
                             new Rectangle(118, 116, 60, 20));

                g.DrawLine(SystemPens.ControlDark, 4, 138, ClientRectangle.Width - 4, 138);

                // recent colors
                for (int x = 8, k = 0; x < 160; k++, x += 20)
                {
                    index++;

                    if (index == hoverColorIndex)
                    {
                        b.Color = SystemColors.Highlight;
                        g.FillRectangle(b, x - 2, 142, 18, 18);
                        g.DrawRectangle(SystemPens.WindowFrame, x - 2, 142, 18, 18);
                    }

                    if (index == selectedColorIndex)
                    {
                        g.DrawRectangle(SystemPens.Highlight, x - 2, 142, 18, 18);
                    }

                    b.Color = recentColor[k];
                    using (SolidBrush sb = new SolidBrush(b.Color))
                    {
                        g.FillRectangle(sb, x, 144, 14, 14);
                        g.DrawRectangle(Pens.Black, x, 144, 14, 14);
                    }
                }

                // transparent
                GraphicsToolkit.DrawTransparentBlock(g, transparentRect);

                using (Brush lineBrush = new LinearGradientBrush(transparentRect,
                                                                 Color.FromArgb(0, Color.White), Color.FromArgb(255, Color.White),
                                                                 LinearGradientMode.Horizontal))
                    g.FillRectangle(lineBrush, transparentRect);

                g.DrawRectangle(Pens.DimGray, transparentRect);

                GraphicsToolkit.FillTriangle(g, 10,
                                             new Point(transparentRect.Left + (int)(currentColor.A * transparentRect.Width / 255),
                                                       transparentRect.Bottom + 6), GraphicsToolkit.TriangleDirection.Up);
            }
        }
예제 #4
0
 protected override void OnPaint(PaintEventArgs e)
 {
     GraphicsToolkit.FillTriangle(e.Graphics, 7, new Point(ClientRectangle.Right - 10,
                                                           ClientRectangle.Top + ClientRectangle.Height / 2 - 1));
 }
예제 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (CheckOnClick)
            {
                using (HatchBrush hb = new HatchBrush(HatchStyle.SmallConfetti, SystemColors.Window, SystemColors.ControlLight))
                {
                    g.FillRectangle(Checked ? hb : SystemBrushes.Window, buttonBounds);
                }
            }
            else
            {
                g.FillRectangle(SystemBrushes.Window, buttonBounds);
            }

            // left button
            g.DrawLine(SystemPens.ControlLight, buttonBounds.X + 1, buttonBounds.Y, buttonBounds.Right, buttonBounds.Y);              // top
            g.DrawLine(SystemPens.ControlLight, buttonBounds.X + 1, buttonBounds.Bottom, buttonBounds.Right, buttonBounds.Bottom);    // bottom
            g.DrawLine(SystemPens.ControlLight, buttonBounds.X, buttonBounds.Y + 1, buttonBounds.X, buttonBounds.Bottom - 1);         // left
            g.DrawLine(SystemPens.ControlLight, buttonBounds.Right, buttonBounds.Y + 1, buttonBounds.Right, buttonBounds.Bottom - 1); // right

            if (isButtonPressed || Checked)
            {
                g.DrawLine(SystemPens.ControlDark, buttonBounds.X + 1, buttonBounds.Y + 1, buttonBounds.Right, buttonBounds.Y + 1);
                g.DrawLine(SystemPens.ControlDark, buttonBounds.X + 1, buttonBounds.Y + 2, buttonBounds.X + 1, buttonBounds.Bottom - 1);             // left
            }

            Rectangle arrowRect = arrowBounds;

            if (isPickerPressed)
            {
                g.DrawLine(SystemPens.ButtonShadow, arrowRect.X, arrowRect.Y + 1, arrowRect.Right - 1, arrowRect.Y + 1);             // top
                g.DrawLine(SystemPens.ControlDark, arrowRect.X, buttonBounds.Y + 2, arrowRect.X, buttonBounds.Bottom - 1);           // right
            }

            // right button
            g.DrawLine(SystemPens.ControlLight, arrowRect.X, arrowRect.Y, arrowRect.Right - 1, arrowRect.Y);              // top
            g.DrawLine(SystemPens.ControlLight, arrowRect.X, arrowRect.Bottom, arrowRect.Right - 1, arrowRect.Bottom);    // bottom
            g.DrawLine(SystemPens.ControlLight, arrowRect.Right, arrowRect.Y + 1, arrowRect.Right, arrowRect.Bottom - 1); // right

            int arrowoffset = isPickerPressed ? 1: 0;

            // arrow
            GraphicsToolkit.FillTriangle(g, arrowSize, new Point(
                                             arrowBounds.X + (arrowBounds.Width) / 2 + arrowoffset,
                                             arrowBounds.Y + (arrowBounds.Height) / 2 - 1 + arrowoffset));

            // color
            Rectangle buttonRect = new Rectangle(3, 3, 16, 16);

            if (isButtonPressed || Checked)
            {
                buttonRect.Offset(1, 1);
            }

            if (Image != null)
            {
                g.DrawImage(Image, buttonRect);
            }
            else
            {
                Rectangle drawRect = new Rectangle(buttonRect.X + (buttonRect.Width - 14) / 2,
                                                   buttonRect.Y + (buttonRect.Height - 14) / 2, 14, 14);

                if (currentColor.IsEmpty)
                {
                    g.DrawRectangle(Pens.Black, drawRect);
                    g.DrawLine(Pens.Black, drawRect.Left, drawRect.Bottom, drawRect.Right, drawRect.Top);
                }
                else
                {
                    using (Pen p = new Pen(currentColor, 2))
                    {
                        using (Pen ep = new Pen(currentColor))
                        {
                            using (Brush b = new SolidBrush(currentColor))
                            {
                                switch (mode)
                                {
                                case ShapeMode.RoundedRect:
                                    g.DrawLine(p, drawRect.X + 1, drawRect.Y, drawRect.Right - 1, drawRect.Top);
                                    g.DrawLine(p, drawRect.X + 1, drawRect.Bottom, drawRect.Right - 1, drawRect.Bottom);
                                    g.DrawLine(p, drawRect.X, drawRect.Y + 1, drawRect.X, drawRect.Bottom - 1);
                                    g.DrawLine(p, drawRect.Right, drawRect.Y + 1, drawRect.Right, drawRect.Bottom - 1);
                                    break;

                                default:
                                case ShapeMode.Rectangle:
                                    g.DrawRectangle(p, drawRect);
                                    break;

                                case ShapeMode.Ellipse:
                                    g.SmoothingMode = SmoothingMode.AntiAlias;
                                    g.DrawEllipse(ep, drawRect);
                                    g.SmoothingMode = SmoothingMode.Default;
                                    break;

                                case ShapeMode.Line:
                                    g.DrawLine(p, drawRect.X, drawRect.Bottom, drawRect.Right, drawRect.Top);
                                    break;

                                case ShapeMode.Arrow:
                                    int y = drawRect.Top + drawRect.Height / 2;
                                    using (Pen arrow = new Pen(currentColor))
                                    {
                                        arrow.CustomEndCap = new AdjustableArrowCap(4, 4);
                                        g.DrawLine(arrow, drawRect.X, y, drawRect.Right, y);
                                    }
                                    break;

                                case ShapeMode.Number:
                                    g.SmoothingMode = SmoothingMode.AntiAlias;
                                    g.DrawEllipse(ep, drawRect);
                                    g.SmoothingMode = SmoothingMode.Default;

                                    using (StringFormat sf = new StringFormat(StringFormat.GenericTypographic))
                                    {
                                        sf.LineAlignment = StringAlignment.Center;
                                        sf.Alignment     = StringAlignment.Center;

                                        string str = currentNumber.ToString();
                                        SizeF  s   = g.MeasureString(str, numberFont, drawRect.Width, sf);

                                        g.DrawString(str, numberFont, b, drawRect, sf);
                                    }
                                    break;

                                case ShapeMode.Text:
                                    using (StringFormat sf = new StringFormat()
                                    {
                                        LineAlignment = StringAlignment.Center,
                                        Alignment = StringAlignment.Center,
                                    })
                                    {
                                        g.DrawString("A", SystemFonts.DialogFont, b, drawRect, sf);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }