private bool FindAndSelectNode(object p, TVItem item) { if (item != null) { if (item.IdenticalData(p)) { SelectedNode = item; return(true); } if (item.Expanded) { foreach (TVItem ch in item.Children) { if (FindAndSelectNode(p, ch)) { return(true); } } } } return(false); }
private int PaintItem(TVItem item, int y, int level, int width, Graphics g) { string itemName = item.GetName(); SizeF textSize = g.MeasureString(itemName, ItemFont); int lastY = y + ItemHeight; item.PaintRect.X = level * ItemHeight; item.PaintRect.Y = y; item.PaintRect.Height = ItemHeight; item.PaintRect.Width = width - level * ItemHeight; //Debugger.Log(0, "", "Draw Item: " + item.Name + ", rect:" + item.PaintRect.ToString() + "\n"); if (item.IdenticalData(p_futureSelection)) { SelectedNode = item; } if (SelectedNode == item) { g.FillRectangle(CellSelBackColor, item.PaintRect); } if (item.IsExpandable()) { int pp = ItemHeight / 5; g.DrawImage((item.Expanded ? Properties.Resources.iconCollapse : Properties.Resources.iconExpand), new Rectangle(item.PaintRect.X, item.PaintRect.Y, ItemHeight, ItemHeight)); } g.DrawString(itemName, ItemFont, Brushes.Black, item.PaintRect.X + ItemHeight, item.PaintRect.Y + (int)(ItemHeight - textSize.Height) / 2); if (item == SelectedNode && item.GetActions() != null) { g.DrawImage(Properties.Resources.IconActions, width - ItemHeight, y, ItemHeight, ItemHeight); } if (item.Expanded) { // padding before lastY += 4; int topY = lastY; if (item.Children != null && item.Children.Count > 0) { // higher level of children level++; g.DrawLine(CellBorderPen, level * ItemHeight, lastY, level * ItemHeight + 8, lastY); for (int i = 0; i < item.Children.Count; i++) { lastY = PaintItem(item.Children[i], lastY, level, width - 2, g); g.DrawLine(CellBorderPen, level * ItemHeight, lastY, level * ItemHeight + 8, lastY); } // vertical line //g.DrawLine(CellBorderPen, width - 1, topY, width - 1, lastY); g.DrawLine(CellBorderPen, level * ItemHeight, topY, level * ItemHeight, lastY); } else { textSize = g.MeasureString("(empty)", ItemEmptyFont); g.DrawString("(empty)", ItemEmptyFont, Brushes.Black, item.PaintRect.X + ItemHeight, lastY + (int)(ItemHeight - textSize.Height) / 2); lastY += ItemHeight; } // padding after lastY += 4; } return(lastY); }