Hi,
have a try on the code below, it seems working but missing the tree line of the first node, I am not sure why.
private void treeViewExec_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (e.Node == treeViewExec.Nodes[0].Nodes[0])
{
TreeNode node = treeViewExec.Nodes[0].Nodes[0];
do
{
int leftBound = node.Bounds.Left ;
string str = "";
if (m_strParentNodeText == "")
{
str = node.Text + "-(";
}
else
{
str = m_strParentNodeText + "-(";
}
using (Font font = new Font(this.Font, FontStyle.Regular))
{
DoDrawing(str, e.Graphics, font, Color.Black, leftBound, node.Bounds.Top);
leftBound = CalculateLeftBoundry(str, e.Graphics, leftBound, font);
DoDrawing(m_nTestcasePass.ToString(), e.Graphics, font, Color.Green, leftBound, node.Bounds.Top);
leftBound = CalculateLeftBoundry(m_nTestcasePass.ToString(), e.Graphics, leftBound, font);
DoDrawing(")", e.Graphics, font, Color.Black, leftBound, node.Bounds.Top);
leftBound = CalculateLeftBoundry(")", e.Graphics, leftBound, font);
DoDrawing(",", e.Graphics, font, Color.Black, leftBound, node.Bounds.Top);
leftBound = CalculateLeftBoundry(",", e.Graphics, leftBound, font);
DoDrawing(m_nTestcaseFailed.ToString(), e.Graphics, font, Color.Red, leftBound, node.Bounds.Top);
}
} while ((node = node.NextNode) != null);
}
else
{
e.DrawDefault = true;
}
}
private int CalculateLeftBoundry(string text, Graphics graphics, int currentLeftBound, Font font)
{
SizeF s = graphics.MeasureString(text, font);
return (currentLeftBound + (int)s.Width);
}
private void DoDrawing(string text, Graphics graphics, Font font, Color color, int leftBoundry, int topBoundry)
{
using (Brush brush = new SolidBrush(color))
{
graphics.DrawString(text, font, brush, leftBoundry, topBoundry);
}
}
It seems to display all child nodes in the colour you wanted. Also I have refactored your code to make more readable.
Regards
Jegan