internal void DrawInternal(Graphics g, RectangleF rect, float zoom, StiAdvancedBorder border)
        {
            using (var pen = new Pen(this.Color))
            {
                pen.DashStyle = StiPenUtils.GetPenStyle(style);
                pen.Width     = (int)(this.Size * zoom);
                pen.StartCap  = LineCap.NoAnchor;
                pen.EndCap    = LineCap.NoAnchor;

                rect = GetAdvancedBorderRectangle(g, rect, zoom, border);

                switch (side)
                {
                case StiBorderSides.Top:
                    if (border.IsTopBorderSidePresent)
                    {
                        g.DrawLine(pen, rect.Left, rect.Top, rect.Right, rect.Top);
                    }
                    break;

                case StiBorderSides.Bottom:
                    if (border.IsBottomBorderSidePresent)
                    {
                        g.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                    }
                    break;

                case StiBorderSides.Left:
                    if (border.IsLeftBorderSidePresent)
                    {
                        g.DrawLine(pen, rect.Left, rect.Top, rect.Left, rect.Bottom);
                    }
                    break;

                case StiBorderSides.Right:
                    if (border.IsRightBorderSidePresent)
                    {
                        g.DrawLine(pen, rect.Right, rect.Top, rect.Right, rect.Bottom);
                    }
                    break;
                }
            }
        }
예제 #2
0
        public static void DrawPenStyle(DrawItemEventArgs e)
        {
            Graphics  g          = e.Graphics;
            Rectangle rect       = e.Bounds;
            Rectangle borderRect = new Rectangle(rect.X + 2, rect.Y + 2, 52, 14);

            #region Fill
            rect.Width--;
            StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText);
            #endregion

            #region Paint border style
            Array obj = Enum.GetValues(typeof(StiPenStyle));

            using (Pen pen = new Pen(Color.Black, 2))
            {
                StiPenStyle penStyle = StiPenStyle.Solid;
                if (e.Index != -1)
                {
                    penStyle = (StiPenStyle)obj.GetValue(e.Index);
                }
                pen.DashStyle = StiPenUtils.GetPenStyle(penStyle);

                g.FillRectangle(Brushes.White, borderRect);

                int center = rect.Top + rect.Height / 2;

                if (penStyle == StiPenStyle.Double)
                {
                    pen.Width = 1;
                    g.DrawLine(pen, 2, center - 1, 54, center - 1);
                    g.DrawLine(pen, 2, center + 1, 54, center + 1);
                }
                else if (penStyle != StiPenStyle.None)
                {
                    g.DrawLine(pen, 2, center, 54, center);
                }
            }

            g.DrawRectangle(Pens.Black, borderRect);
            #endregion

            #region Paint name
            using (Font font = new Font("Arial", 8))
            {
                using (StringFormat stringFormat = new StringFormat())
                {
                    stringFormat.LineAlignment = StringAlignment.Center;

                    string name = ((StiPenStyle)obj.GetValue(e.Index)).ToString();

                    string locName = StiLocalization.Get("PropertyEnum", "StiPenStyle" + name);

                    if (locName != null)
                    {
                        name = locName;
                    }

                    e.Graphics.DrawString(name,
                                          font, Brushes.Black,
                                          new Rectangle(55, rect.Top + 4, rect.Width - 18, 10),
                                          stringFormat);
                }
            }
            #endregion
        }
예제 #3
0
        /// <summary>
        /// Draws this border on the indicated Graphics.
        /// </summary>
        /// <param name="g">Graphics on which a border can be drawn.</param>
        /// <param name="rect">The rectangle that indicates an area of the border drawing.</param>
        /// <param name="zoom">The scale of a border to draw.</param>
        /// <param name="emptyColor">The color of space between double lines (used only when border style equal Double).</param>
        public virtual void Draw(Graphics g, RectangleF rect, float zoom, Color emptyColor, bool drawBorderFormatting, bool drawBorderSides)
        {
            if (bits == null)
            {
                return;
            }
            if (IsDefault)
            {
                return;
            }
            if (drawBorderFormatting)
            {
                DrawBorderShadow(g, rect, zoom);
            }

            if (drawBorderSides)
            {
                Pen emptyPen = null;
                using (Pen pen = new Pen(bits.Color))
                {
                    if (bits.Style == StiPenStyle.Double)
                    {
                        emptyPen = new Pen(emptyColor);
                    }

                    pen.DashStyle = StiPenUtils.GetPenStyle(bits.Style);

                    #region Painting
                    if (bits.Style != StiPenStyle.None)
                    {
                        pen.Width    = (int)(bits.Size * zoom);
                        pen.StartCap = LineCap.Square;
                        pen.EndCap   = LineCap.Square;

                        RectangleF rectIn  = rect;
                        RectangleF rectOut = rect;

                        if (bits.Style == StiPenStyle.Double)
                        {
                            rectIn.Inflate(-1, -1);
                            rectOut.Inflate(1, 1);
                            pen.Width = 1;
                        }

                        float left   = 0;
                        float right  = 0;
                        float top    = 0;
                        float bottom = 0;

                        #region All border sides
                        if (this.IsAllBorderSidesPresent)
                        {
                            if (bits.Style == StiPenStyle.Double)
                            {
                                g.DrawRectangle(emptyPen, rect.X, rect.Y, rect.Width, rect.Height);
                                g.DrawRectangle(pen, rectIn.X, rectIn.Y, rectIn.Width, rectIn.Height);
                                g.DrawRectangle(pen, rectOut.X, rectOut.Y, rectOut.Width, rectOut.Height);
                            }
                            else
                            {
                                g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
                            }
                        }
                        #endregion

                        else
                        {
                            #region Top border side
                            if (this.IsTopBorderSidePresent)
                            {
                                left  = rectIn.Left;
                                right = rectIn.Right;

                                if (!IsLeftBorderSidePresent)
                                {
                                    left = rectOut.Left;
                                }
                                if (!IsRightBorderSidePresent)
                                {
                                    right = rectOut.Right;
                                }

                                if (bits.Style == StiPenStyle.Double)
                                {
                                    g.DrawLine(emptyPen, rect.Left, rect.Top, rect.Right, rect.Top);
                                    g.DrawLine(pen, left, rectIn.Top, right, rectIn.Top);
                                    g.DrawLine(pen, rectOut.Left, rectOut.Top, rectOut.Right, rectOut.Top);
                                }
                                else
                                {
                                    g.DrawLine(pen, rect.Left, rect.Top, rect.Right, rect.Top);
                                }
                            }
                            #endregion

                            #region Left border side
                            if (this.IsLeftBorderSidePresent)
                            {
                                top    = rectIn.Top;
                                bottom = rectIn.Bottom;

                                if (!IsTopBorderSidePresent)
                                {
                                    top = rectOut.Top;
                                }
                                if (!IsBottomBorderSidePresent)
                                {
                                    bottom = rectOut.Bottom;
                                }

                                if (Style == StiPenStyle.Double)
                                {
                                    g.DrawLine(emptyPen, rect.Left, rect.Top, rect.Left, rect.Bottom);
                                    g.DrawLine(pen, rectIn.Left, top, rectIn.Left, bottom);
                                    g.DrawLine(pen, rectOut.Left, rectOut.Top, rectOut.Left, rectOut.Bottom);
                                }
                                else
                                {
                                    g.DrawLine(pen, rect.Left, rect.Top, rect.Left, rect.Bottom);
                                }
                            }
                            #endregion

                            #region Bottom border side
                            if (this.IsBottomBorderSidePresent)
                            {
                                left  = rectIn.Left;
                                right = rectIn.Right;

                                if (!IsLeftBorderSidePresent)
                                {
                                    left = rectOut.Left;
                                }
                                if (!IsRightBorderSidePresent)
                                {
                                    right = rectOut.Right;
                                }

                                if (bits.Style == StiPenStyle.Double)
                                {
                                    g.DrawLine(emptyPen, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                                    g.DrawLine(pen, left, rectIn.Bottom, right, rectIn.Bottom);
                                    g.DrawLine(pen, rectOut.Left, rectOut.Bottom, rectOut.Right, rectOut.Bottom);
                                }
                                else
                                {
                                    g.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                                }
                            }
                            #endregion

                            #region Right border side
                            if (this.IsRightBorderSidePresent)
                            {
                                top    = rectIn.Top;
                                bottom = rectIn.Bottom;

                                if (!IsTopBorderSidePresent)
                                {
                                    top = rectOut.Top;
                                }
                                if (!IsBottomBorderSidePresent)
                                {
                                    bottom = rectOut.Bottom;
                                }

                                if (bits.Style == StiPenStyle.Double)
                                {
                                    g.DrawLine(emptyPen, rect.Right, rect.Top, rect.Right, rect.Bottom);
                                    g.DrawLine(pen, rectIn.Right, top, rectIn.Right, bottom);
                                    g.DrawLine(pen, rectOut.Right, rectOut.Top, rectOut.Right, rectOut.Bottom);
                                }
                                else
                                {
                                    g.DrawLine(pen, rect.Right, rect.Top, rect.Right, rect.Bottom);
                                }
                            }
                            #endregion
                        }
                        if (emptyPen != null)
                        {
                            emptyPen.Dispose();
                            emptyPen = null;
                        }
                    }
                    #endregion
                }
            }
        }
        private void DrawDoubleInternal(Graphics g, RectangleF rect, float zoom, Color emptyColor, StiAdvancedBorder border)
        {
            using (var emptyPen = new Pen(emptyColor))
                using (var pen = new Pen(this.Color, 1))
                {
                    pen.DashStyle = StiPenUtils.GetPenStyle(style);
                    pen.StartCap  = LineCap.Square;
                    pen.EndCap    = LineCap.Square;

                    var rectIn  = rect;
                    var rectOut = rect;

                    rectIn.Inflate(-1, -1);
                    rectOut.Inflate(1, 1);

                    var left   = 0f;
                    var right  = 0f;
                    var top    = 0f;
                    var bottom = 0f;

                    switch (side)
                    {
                        #region Top
                    case StiBorderSides.Top:
                        if (border.IsTopBorderSidePresent)
                        {
                            left  = rectIn.Left;
                            right = rectIn.Right;

                            if (!border.IsLeftBorderSidePresent)
                            {
                                left = rectOut.Left;
                            }
                            if (!border.IsRightBorderSidePresent)
                            {
                                right = rectOut.Right;
                            }

                            g.DrawLine(emptyPen, rect.Left, rect.Top, rect.Right, rect.Top);
                            g.DrawLine(pen, left, rectIn.Top, right, rectIn.Top);
                            g.DrawLine(pen, rectOut.Left, rectOut.Top, rectOut.Right, rectOut.Top);
                        }
                        break;
                        #endregion

                        #region Bottom
                    case StiBorderSides.Bottom:
                        if (border.IsBottomBorderSidePresent)
                        {
                            left  = rectIn.Left;
                            right = rectIn.Right;

                            if (!border.IsLeftBorderSidePresent)
                            {
                                left = rectOut.Left;
                            }
                            if (!border.IsRightBorderSidePresent)
                            {
                                right = rectOut.Right;
                            }

                            g.DrawLine(emptyPen, rect.Left, rect.Bottom, rect.Right, rect.Bottom);
                            g.DrawLine(pen, left, rectIn.Bottom, right, rectIn.Bottom);
                            g.DrawLine(pen, rectOut.Left, rectOut.Bottom, rectOut.Right, rectOut.Bottom);
                        }
                        break;
                        #endregion

                        #region Left
                    case StiBorderSides.Left:
                        if (border.IsLeftBorderSidePresent)
                        {
                            top    = rectIn.Top;
                            bottom = rectIn.Bottom;

                            if (!border.IsTopBorderSidePresent)
                            {
                                top = rectOut.Top;
                            }
                            if (!border.IsBottomBorderSidePresent)
                            {
                                bottom = rectOut.Bottom;
                            }

                            g.DrawLine(emptyPen, rect.Left, rect.Top, rect.Left, rect.Bottom);
                            g.DrawLine(pen, rectIn.Left, top, rectIn.Left, bottom);
                            g.DrawLine(pen, rectOut.Left, rectOut.Top, rectOut.Left, rectOut.Bottom);
                        }
                        break;
                        #endregion

                        #region Right
                    case StiBorderSides.Right:
                        if (border.IsRightBorderSidePresent)
                        {
                            top    = rectIn.Top;
                            bottom = rectIn.Bottom;

                            if (!border.IsTopBorderSidePresent)
                            {
                                top = rectOut.Top;
                            }
                            if (!border.IsBottomBorderSidePresent)
                            {
                                bottom = rectOut.Bottom;
                            }

                            g.DrawLine(emptyPen, rect.Right, rect.Top, rect.Right, rect.Bottom);
                            g.DrawLine(pen, rectIn.Right, top, rectIn.Right, bottom);
                            g.DrawLine(pen, rectOut.Right, rectOut.Top, rectOut.Right, rectOut.Bottom);
                        }
                        break;
                        #endregion
                    }
                }
        }