diff --git a/DarkUI/Controls/DarkTreeView.cs b/DarkUI/Controls/DarkTreeView.cs index bfecb86..cf52f67 100644 --- a/DarkUI/Controls/DarkTreeView.cs +++ b/DarkUI/Controls/DarkTreeView.cs @@ -1262,10 +1262,33 @@ private void DrawNode(DarkTreeNode node, Graphics g) } // 5. Draw child nodes + DrawChildNodes(node, g); + + } + + /// + /// Recursively paints only the nodes and child nodes within the viewport. + /// + private void DrawChildNodes(DarkTreeNode node, Graphics g) + { if (node.Expanded) { foreach (var childNode in node.Nodes) - DrawNode(childNode, g); + { + + if (childNode.Expanded) + DrawChildNodes(childNode, g); + + bool isInTopView = Viewport.Top <= childNode.FullArea.Y; + bool isWithin = childNode.FullArea.Y < Viewport.Top + Viewport.Height; + bool isPastBottomView = childNode.FullArea.Y > Viewport.Top + Viewport.Height; + + if (isInTopView && isWithin) + DrawNode(childNode, g); + + if (isPastBottomView) + break; + } } }