void DrawFolds(Graphics g, RectangleF rectangle, bool isOpened, bool isSelected)
        {
            HighlightColor foldMarkerColor  = TextArea.Document.HighlightingStrategy.GetColorFor("FoldMarker");
            HighlightColor foldLineColor    = TextArea.Document.HighlightingStrategy.GetColorFor("FoldLine");
            HighlightColor selectedFoldLine = TextArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine");

            Color foregroundColor = isSelected ? selectedFoldLine.Color : foldLineColor.Color;
            Color backgroundColor = foldMarkerColor.BackgroundColor;

            Pen   foldLinePen     = BrushRegistry.GetPen(foregroundColor);
            Pen   foldMarkerPen   = BrushRegistry.GetPen(foldMarkerColor.Color);
            Brush backgroundBrush = BrushRegistry.GetBrush(backgroundColor);

            Rectangle intRect = new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);

            g.FillRectangle(backgroundBrush, intRect);
            g.DrawRectangle(foldLinePen, intRect);

            int space = (int)Math.Round(rectangle.Height / 8.0) + 1;
            int mid   = intRect.Height / 2 + intRect.Height % 2;

            // Draw horizontal line (-)
            g.DrawLine(foldMarkerPen,
                       rectangle.X + space,
                       rectangle.Y + mid,
                       rectangle.X + rectangle.Width - space,
                       rectangle.Y + mid);

            if (!isOpened)
            {
                // Draw vertical line (+)
                g.DrawLine(foldMarkerPen, rectangle.X + mid, rectangle.Y + space, rectangle.X + mid, rectangle.Y + rectangle.Height - space);
            }
        }
        void PaintFoldMarker(Graphics g, int lineNumber, Rectangle drawingRectangle)
        {
            HighlightColor foldLineColor         = TextArea.Document.HighlightingStrategy.GetColorFor("FoldLine");
            HighlightColor selectedFoldLineColor = TextArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine");

            List <Fold> foldingsWithStart = TextArea.Document.FoldingManager.GetFoldsWithStartAt(lineNumber);
            List <Fold> foldingsBetween   = TextArea.Document.FoldingManager.GetFoldsContainingLine(lineNumber);
            List <Fold> foldingsWithEnd   = TextArea.Document.FoldingManager.GetFoldsWithEndAt(lineNumber);

            bool isFoldStart = foldingsWithStart.Count > 0;
            bool isBetween   = foldingsBetween.Count > 0;
            bool isFoldEnd   = foldingsWithEnd.Count > 0;

            bool isStartSelected   = SelectedFoldFrom(foldingsWithStart);
            bool isBetweenSelected = SelectedFoldFrom(foldingsBetween);
            bool isEndSelected     = SelectedFoldFrom(foldingsWithEnd);

            int foldMarkerSize = (int)Math.Round(TextArea.TextView.LineHeight * 0.57f);

            foldMarkerSize -= (foldMarkerSize) % 2;
            int foldMarkerYPos = drawingRectangle.Y + (drawingRectangle.Height - foldMarkerSize) / 2;
            int xPos           = drawingRectangle.X + (drawingRectangle.Width - foldMarkerSize) / 2 + foldMarkerSize / 2;


            if (isFoldStart)
            {
                bool isVisible         = true;
                bool moreLinedOpenFold = false;
                foreach (Fold fold in foldingsWithStart)
                {
                    if (fold.IsFolded)
                    {
                        isVisible = false;
                    }
                    else
                    {
                        moreLinedOpenFold = fold.EndLine > fold.StartLine;
                    }
                }

                bool isFoldEndFromUpperFold = false;
                foreach (Fold fold in foldingsWithEnd)
                {
                    if (fold.EndLine > fold.StartLine && !fold.IsFolded)
                    {
                        isFoldEndFromUpperFold = true;
                    }
                }

                RectangleF foldMarkerRectangle = new RectangleF(drawingRectangle.X + (drawingRectangle.Width - foldMarkerSize) / 2,
                                                                foldMarkerYPos,
                                                                foldMarkerSize,
                                                                foldMarkerSize);
                DrawFolds(g, foldMarkerRectangle, isVisible, isStartSelected);

                // draw line above fold marker
                if (isBetween || isFoldEndFromUpperFold)
                {
                    Pen pen = BrushRegistry.GetPen(isBetweenSelected ? selectedFoldLineColor.Color : foldLineColor.Color);
                    g.DrawLine(pen, xPos, drawingRectangle.Top, xPos, foldMarkerYPos - 1);
                }

                // draw line below fold marker
                if (isBetween || moreLinedOpenFold)
                {
                    bool  isSelected = isEndSelected || (isStartSelected && isVisible) || isBetweenSelected;
                    Color color      = (isSelected) ? selectedFoldLineColor.Color : foldLineColor.Color;
                    Pen   pen        = BrushRegistry.GetPen(color);
                    g.DrawLine(pen, xPos, foldMarkerYPos + foldMarkerSize + 1, xPos, drawingRectangle.Bottom);
                }
            }
            else if (isFoldEnd)
            {
                int midy = drawingRectangle.Top + drawingRectangle.Height / 2;

                // draw fold end marker
                Color color = isEndSelected ? selectedFoldLineColor.Color : foldLineColor.Color;
                Pen   pen   = BrushRegistry.GetPen(color);
                g.DrawLine(pen, xPos, midy, xPos + foldMarkerSize / 2, midy);

                // draw line above fold end marker
                // must be drawn after fold marker because it might have a different color than the fold marker
                color = (isBetweenSelected || isEndSelected) ? selectedFoldLineColor.Color : foldLineColor.Color;
                pen   = BrushRegistry.GetPen(color);
                g.DrawLine(pen, xPos, drawingRectangle.Top, xPos, midy);

                // draw line below fold end marker
                if (isBetween)
                {
                    color = isBetweenSelected ? selectedFoldLineColor.Color : foldLineColor.Color;
                    pen   = BrushRegistry.GetPen(color);
                    g.DrawLine(pen, xPos, midy + 1, xPos, drawingRectangle.Bottom);
                }
            }
            else if (isBetween)
            {
                // just draw the line :)
                Color color = isBetweenSelected ? selectedFoldLineColor.Color : foldLineColor.Color;
                Pen   pen   = BrushRegistry.GetPen(color);
                g.DrawLine(pen, xPos, drawingRectangle.Top, xPos, drawingRectangle.Bottom);
            }
        }