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); } }