Example #1
0
        protected void RenderRowBorder(Graphics g, TextRowVisualStyle style, Rectangle r)
        {
            if (style.BorderPattern == null ||
                style.BorderThickness == null || style.BorderColor == null)
            {
                return;
            }

            Rectangle t = r;
            t.X += style.Margin.Left;
            t.Width -= style.Margin.Horizontal;

            t.Y += style.Margin.Top;
            t.Height -= style.Margin.Vertical;

            if (style.BorderColor.IsUniform == true &&
                style.BorderThickness.IsUniform == true && style.BorderPattern.IsUniform == true)
            {
                if (style.BorderThickness.Top > 0 && style.BorderColor.Top.IsEmpty == false)
                {
                    t.Width -= style.BorderThickness.Top;
                    t.Height -= style.BorderThickness.Top;

                    using (Pen pen = new
                        Pen(style.BorderColor.Top, style.BorderThickness.Top))
                    {
                        LinePattern pattern = (style.BorderPattern.Top == LinePattern.NotSet)
                            ? LinePattern.Solid : style.BorderPattern.Top;

                        pen.DashStyle = (DashStyle)pattern;

                        g.DrawRectangle(pen, t);
                    }
                }
            }
            else
            {
                Pen[] pens = style.GetBorderPens();

                if (pens[(int)BorderSide.Right] != null)
                {
                    int right = t.Right - (style.BorderThickness.Right / 2);

                    g.DrawLine(pens[(int)BorderSide.Right], right, t.Top, right, t.Bottom);
                }

                if (pens[(int)BorderSide.Bottom] != null)
                {
                    int bottom = t.Bottom - ((style.BorderThickness.Bottom - 1) / 2);

                    g.DrawLine(pens[(int)BorderSide.Bottom], t.X, bottom, t.Right, bottom);
                }

                if (pens[(int)BorderSide.Left] != null)
                    g.DrawLine(pens[(int)BorderSide.Left], t.X, t.Top, t.X, t.Bottom);

                if (pens[(int)BorderSide.Top] != null)
                    g.DrawLine(pens[(int)BorderSide.Top], t.X, t.Top, t.Right, t.Top);

                foreach (Pen pen in pens)
                {
                    if (pen != null)
                        pen.Dispose();
                }
            }
        }