示例#1
0
        public override void PaintControl(RichTextBox control, ControlPaintArgs args)
        {
            INode    controlNode = new ControlNode(control);
            IRuleset ruleset     = args.StyleSheet.GetRuleset(controlNode);

            RenderUtilities.ApplyColorProperties(control, ruleset);

            Rectangle clientRect = control.ClientRectangle;
            Rectangle borderRect = new Rectangle(clientRect.X - 3, clientRect.Y - 3, clientRect.Width + 6, clientRect.Height + 6);

            ScrollBars visibleScrollbars = ControlUtilities.GetVisibleScrollBars(control);

            if (visibleScrollbars.HasFlag(ScrollBars.Vertical))
            {
                borderRect = new Rectangle(borderRect.X, borderRect.Y, borderRect.Width + SystemInformation.VerticalScrollBarWidth, borderRect.Height);
            }

            if (visibleScrollbars.HasFlag(ScrollBars.Horizontal))
            {
                borderRect = new Rectangle(borderRect.X, borderRect.Y, borderRect.Width, borderRect.Height + SystemInformation.HorizontalScrollBarHeight);
            }

            args.PaintBackground(borderRect);
            args.PaintBorder(borderRect);
        }
示例#2
0
        private void PaintGenericControl(ControlPaintArgs e)
        {
            IRuleset ruleset = e.StyleSheet.GetRuleset(new ControlNode(e.Control));

            RenderUtilities.ApplyColorProperties(e.Control, ruleset);

            e.PaintBackground();
            e.PaintBorder();
        }
示例#3
0
        // Public members

        public override void PaintControl(NumericUpDown control, ControlPaintArgs e)
        {
            IRuleset ruleset = e.StyleSheet.GetRuleset(control);

            // Update the color of the NumericUpdateDown, which updates the color of the UpDownEdit (inheriting from TextBox).

            RenderUtilities.ApplyColorProperties(control, ruleset);

            // Like TextBoxes, NumericUpDowns are 23 pixels high.
            // Because the NumericUpDown has BorderStyle.None, we need to adjust it to look like a bordered control.

            Rectangle clientRect = control.ClientRectangle;

            int x = clientRect.X - 2;
            int y = clientRect.Y - 2;
            int w = clientRect.Width + 3;
            int h = clientRect.Height + 4;

            double topWidth    = ruleset.BorderTopWidth?.Value ?? 0;
            double rightWidth  = ruleset.BorderRightWidth?.Value ?? 0;
            double bottomWidth = ruleset.BorderBottomWidth?.Value ?? 0;
            double leftWidth   = ruleset.BorderLeftWidth?.Value ?? 0;

            if (topWidth <= 1)
            {
                topWidth = 0;
            }

            if (rightWidth <= 1)
            {
                rightWidth = 0;
            }

            if (bottomWidth <= 1)
            {
                bottomWidth = 0;
            }

            if (leftWidth <= 1)
            {
                leftWidth = 0;
            }

            x -= (int)leftWidth;
            y -= (int)topWidth;
            w += (int)leftWidth + (int)rightWidth;
            h += (int)topWidth + (int)bottomWidth;

            Rectangle drawRect = new Rectangle(x, y, w, h);

            e.StyleRenderer.PaintBackground(e.Graphics, drawRect, ruleset);
            e.StyleRenderer.PaintBorder(e.Graphics, drawRect, ruleset);
        }
示例#4
0
        // Protected members

        protected virtual void PaintBackground(TreeView control, ControlPaintArgs args)
        {
            IRuleset  ruleset    = args.StyleSheet.GetRuleset(control);
            Rectangle borderRect = RenderUtilities.GetOuterBorderRectangle(control, ruleset);

            if (ruleset.BackgroundColor.HasValue() && ruleset.BackgroundColor.Value != control.BackColor)
            {
                control.BackColor = ruleset.BackgroundColor.Value;
            }

            args.PaintBackground(borderRect);
            args.PaintBorder(borderRect);
        }
        public override void PaintControl(DataGridView control, ControlPaintArgs args)
        {
            // Draw the background/border of the control.

            IRuleset  ruleset    = args.StyleSheet.GetRuleset(control);
            Rectangle borderRect = RenderUtilities.GetOuterBorderRectangle(control, ruleset);

            if (ruleset.BackgroundColor.HasValue() && ruleset.BackgroundColor.Value != control.BackColor)
            {
                control.BackgroundColor = ruleset.BackgroundColor.Value;
            }

            args.PaintBackground(borderRect);
            args.PaintBorder(borderRect);
        }
        // Public members

        public override void PaintControl(ComboBox control, ControlPaintArgs e)
        {
            IRuleset ruleset = e.StyleSheet.GetRuleset(control);

            RenderUtilities.ApplyColorProperties(control, ruleset);

            Rectangle clientRect = control.ClientRectangle;

            e.PaintBackground();

            // Match the foreground bounds of the default control.
            // The text is cut off behind the drop-down arrow.

            Rectangle textRect = new Rectangle(clientRect.X + 1, clientRect.Y, clientRect.Width - 21, clientRect.Height);

            e.PaintText(textRect);

            PaintDropDownArrow(control, e);

            e.PaintBorder();
        }
        // Public members

        public override void PaintControl(ListBox control, ControlPaintArgs e)
        {
            Rectangle borderRect = RenderUtilities.GetOuterBorderRectangle(control, e.StyleSheet.GetRuleset(control));

            if (ControlUtilities.GetVisibleScrollBars(control).HasFlag(ScrollBars.Vertical))
            {
                borderRect = new Rectangle(borderRect.X, borderRect.Y, borderRect.Width + SystemInformation.VerticalScrollBarWidth, borderRect.Height);
            }

            e.PaintBackground();

            if (!e.ParentDraw)
            {
                GraphicsState graphicsState = e.Graphics.Save();

                e.ClipToBorder(borderRect);

                PaintItems(control, e);

                e.Graphics.Restore(graphicsState);
            }

            e.PaintBorder(borderRect);
        }
示例#8
0
        // Public members

        public override void PaintControl(TextBox control, ControlPaintArgs e)
        {
            IRuleset ruleset = e.StyleSheet.GetRuleset(control);

            // Update the color of the TextBox itself.

            RenderUtilities.ApplyColorProperties(control, ruleset);

            // Draw the background the TextBox.
            // The height of regular TextBoxes is 23 pixels, with 3 pixels of horizontal padding.

            Rectangle clientRect = control.ClientRectangle;

            int x = clientRect.X - 3;
            int y = clientRect.Y - 4;
            int w = clientRect.Width + 6;
            int h = clientRect.Height + 7;

            double topWidth    = ruleset.BorderTopWidth?.Value ?? 0;
            double rightWidth  = ruleset.BorderRightWidth?.Value ?? 0;
            double bottomWidth = ruleset.BorderBottomWidth?.Value ?? 0;
            double leftWidth   = ruleset.BorderLeftWidth?.Value ?? 0;

            if (topWidth <= 1)
            {
                topWidth = 0;
            }

            if (rightWidth <= 1)
            {
                rightWidth = 0;
            }

            if (bottomWidth <= 1)
            {
                bottomWidth = 0;
            }

            if (leftWidth <= 1)
            {
                leftWidth = 0;
            }

            x -= (int)leftWidth;
            y -= (int)topWidth;
            w += (int)leftWidth + (int)rightWidth;
            h += (int)topWidth + (int)bottomWidth;

            ScrollBars visibleScrollbars = ControlUtilities.GetVisibleScrollBars(control);

            if (visibleScrollbars.HasFlag(ScrollBars.Vertical))
            {
                w += SystemInformation.VerticalScrollBarWidth;
            }

            if (visibleScrollbars.HasFlag(ScrollBars.Horizontal))
            {
                h += SystemInformation.HorizontalScrollBarHeight;
            }

            //GraphicsState graphicsState = graphics.Save();

            Rectangle drawRect = new Rectangle(x, y, w, h);

            //graphics.SetClip(drawRect);

            e.StyleRenderer.PaintBackground(e.Graphics, drawRect, ruleset);
            e.StyleRenderer.PaintBorder(e.Graphics, drawRect, ruleset);

            //graphics.Restore(graphicsState);
        }
示例#9
0
        public void PaintBorder(Graphics graphics, Rectangle rectangle, IRuleset ruleset)
        {
            GraphicsState state = graphics.Save();

            bool hasRadius = ruleset.GetBorderRadii().Any(r => r > 0);

            if (hasRadius)
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }

            double topWidth    = ruleset.BorderTopWidth?.Value ?? 0;
            double rightWidth  = ruleset.BorderRightWidth?.Value ?? 0;
            double bottomWidth = ruleset.BorderBottomWidth?.Value ?? 0;
            double leftWidth   = ruleset.BorderLeftWidth?.Value ?? 0;

            double topLeftRadius     = ruleset.BorderTopLeftRadius?.Value ?? 0;
            double topRightRadius    = ruleset.BorderTopRightRadius?.Value ?? 0;
            double bottomRightRadius = ruleset.BorderBottomRightRadius?.Value ?? 0;
            double bottomLeftRadius  = ruleset.BorderBottomLeftRadius?.Value ?? 0;

            double horizontalBorderWidth = leftWidth + rightWidth;
            double verticalBorderWidth   = topWidth + bottomWidth;

            int rectX      = rectangle.X + (int)(leftWidth / 2);
            int rectY      = rectangle.Y + (int)(topWidth / 2);
            int rectWidth  = rectangle.Width - (int)(horizontalBorderWidth / 2);
            int rectHeight = rectangle.Height - (int)(verticalBorderWidth / 2);

            Rectangle drawRect = new Rectangle(rectX, rectY, rectWidth - (rightWidth == 1 && leftWidth <= 0 ? 1 : 0), rectHeight - (bottomWidth == 1 && topWidth <= 0 ? 1 : 0));

            float opacity = (float)(ruleset.Opacity?.Value ?? 1.0f);

            using (Pen pen = new Pen(Color.Black)) {
                pen.Alignment = PenAlignment.Center;
                pen.StartCap  = LineCap.Square;

                if (topWidth > 0)
                {
                    StyleSheets.BorderStyle borderStyle = ruleset.BorderTopStyle?.Value ?? StyleSheets.BorderStyle.Solid;

                    if (borderStyle != StyleSheets.BorderStyle.None && borderStyle != StyleSheets.BorderStyle.Hidden)
                    {
                        pen.Width     = (float)topWidth;
                        pen.Color     = RenderUtilities.GetColorWithAlpha(ruleset.BorderTopColor?.Value ?? default, opacity);
                        pen.DashStyle = RenderUtilities.GetDashStyle(borderStyle);

                        using (GraphicsPath path = RenderUtilities.CreateBorderPath(drawRect, BorderPathType.Top, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius))
                            graphics.DrawPath(pen, path);
                    }
                }

                if (rightWidth > 0)
                {
                    StyleSheets.BorderStyle borderStyle = ruleset.BorderRightStyle?.Value ?? StyleSheets.BorderStyle.Solid;

                    if (borderStyle != StyleSheets.BorderStyle.None && borderStyle != StyleSheets.BorderStyle.Hidden)
                    {
                        pen.Width     = (float)rightWidth;
                        pen.Color     = RenderUtilities.GetColorWithAlpha(ruleset.BorderRightColor?.Value ?? default, opacity);
                        pen.DashStyle = RenderUtilities.GetDashStyle(borderStyle);

                        using (GraphicsPath path = RenderUtilities.CreateBorderPath(drawRect, BorderPathType.Right, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius))
                            graphics.DrawPath(pen, path);
                    }
                }

                if (bottomWidth > 0)
                {
                    StyleSheets.BorderStyle borderStyle = ruleset.BorderBottomStyle?.Value ?? StyleSheets.BorderStyle.Solid;

                    if (borderStyle != StyleSheets.BorderStyle.None && borderStyle != StyleSheets.BorderStyle.Hidden)
                    {
                        pen.Width     = (float)bottomWidth;
                        pen.Color     = RenderUtilities.GetColorWithAlpha(ruleset.BorderBottomColor?.Value ?? default, opacity);
                        pen.DashStyle = RenderUtilities.GetDashStyle(borderStyle);

                        using (GraphicsPath path = RenderUtilities.CreateBorderPath(drawRect, BorderPathType.Bottom, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius))
                            graphics.DrawPath(pen, path);
                    }
                }

                if (leftWidth > 0)
                {
                    StyleSheets.BorderStyle borderStyle = ruleset.BorderLeftStyle?.Value ?? StyleSheets.BorderStyle.Solid;

                    if (borderStyle != StyleSheets.BorderStyle.None && borderStyle != StyleSheets.BorderStyle.Hidden)
                    {
                        pen.Width     = (float)leftWidth;
                        pen.Color     = RenderUtilities.GetColorWithAlpha(ruleset.BorderLeftColor?.Value ?? default, opacity);
                        pen.DashStyle = RenderUtilities.GetDashStyle(borderStyle);

                        using (GraphicsPath path = RenderUtilities.CreateBorderPath(drawRect, BorderPathType.Left, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius))
                            graphics.DrawPath(pen, path);
                    }
                }
            }

            graphics.Restore(state);
        }
示例#10
0
        // Public members

        public void PaintBackground(Graphics graphics, Rectangle rectangle, IRuleset ruleset)
        {
            GraphicsState state = graphics.Save();

            bool hasRadius       = ruleset.GetBorderRadii().Any(r => r > 0);
            bool hasRightRadius  = hasRadius && (ruleset.BorderTopRightRadius?.Value > 0 || ruleset.BorderBottomRightRadius?.Value > 0);
            bool hasBottomRadius = hasRadius && (ruleset.BorderBottomLeftRadius?.Value > 0 || ruleset.BorderBottomRightRadius?.Value > 0);

            if (hasRadius)
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
            }

            // Draw the background color.

            Rectangle backgroundRect = rectangle;

            // If the rectangle has right or bottom corner radii, the bounds must be decreased to ensure the curve is not clipped.

            if (hasRadius)
            {
                backgroundRect = new Rectangle(rectangle.X, rectangle.Y, rectangle.Width - (hasRightRadius ? 1 : 0), rectangle.Height - (hasBottomRadius ? 1 : 0));
            }

            int topLeft     = (int)(ruleset.BorderTopLeftRadius?.Value ?? 0);
            int topRight    = (int)(ruleset.BorderTopRightRadius?.Value ?? 0);
            int bottomLeft  = (int)(ruleset.BorderBottomLeftRadius?.Value ?? 0);
            int bottomRight = (int)(ruleset.BorderBottomRightRadius?.Value ?? 0);

            if (ruleset.BackgroundColor.HasValue())
            {
                Color backgroundColor = ruleset.BackgroundColor?.Value ?? SystemColors.Control;

                if (ruleset.Opacity.HasValue())
                {
                    backgroundColor = RenderUtilities.GetColorWithAlpha(backgroundColor, (float)ruleset.Opacity.Value);
                }

                using (Brush brush = new SolidBrush(backgroundColor)) {
                    if (!hasRadius)
                    {
                        graphics.FillRectangle(brush, backgroundRect);
                    }
                    else
                    {
                        graphics.FillRoundedRectangle(brush, backgroundRect, topLeft, topRight, bottomLeft, bottomRight);
                    }
                }
            }

            // Draw the background image.

            if (ruleset.BackgroundImage.HasValue())
            {
                ClipToBorder(graphics, backgroundRect, ruleset);

                foreach (IImage image in ruleset.BackgroundImage.Value.Images)
                {
                    graphics.DrawImage(image, backgroundRect);
                }
            }

            graphics.Restore(state);
        }