Pessoal Já acheiAchei a solução {na própria https://docs.microsoft.com/pt-br/dotnet/api/system.windows.forms.treeview.drawnode?view=net-5.0documentação } na própria documentação ensina porem n está tão visível .... oSegue o código completo =>
Font tagFont = new Font(FontFamily.GenericSansSerif,8, FontStyle.Bold);
treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
treeView1.DrawNode += new DrawTreeNodeEventHandler(Ty_DrawNode);
treeView1.MouseDown += new MouseEventHandler(myTreeView_MouseDown);
treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
treeView1.DrawNode += new DrawTreeNodeEventHandler(Ty_DrawNode);
treeView1.MouseDown += new MouseEventHandler(myTreeView_MouseDown);
private void Ty_DrawNode(Object ob,DrawTreeNodeEventArgs e)
{
if ((e.State & TreeNodeStates.Selected)!= 0)
{
e.Graphics.FillRectangle(Brushes.Red, NodeBounds(e.Node));
Font nodefont = e.Node.NodeFont;
if (nodefont == null) nodefont = ((TreeView)ob).Font;
e.Graphics.DrawString(e.Node.Text, nodefont, Brushes.White,
Rectangle.Inflate(e.Bounds, 2, 0));
}
else
{
e.DrawDefault = true;
}
}
private RectangleF NodeBounds(TreeNode node)
{
Rectangle bounds = node.Bounds;
if (node.Tag != null)
{
Graphics g = treeView1.CreateGraphics();
int tagwhite = (int)g.MeasureString(node.Tag.ToString(),
tagFont).Width;
bounds.Offset(tagwhite, 0);
bounds = Rectangle.Inflate(bounds, tagwhite, 0);
g.Dispose();
}
return bounds;
}
private void myTreeView_MouseDown(object sender, MouseEventArgs e)
{
TreeNode clickedNode = treeView1.GetNodeAt(e.X, e.Y);
if (NodeBounds(clickedNode).Contains(e.X, e.Y))
{
treeView1.SelectedNode = clickedNode;
}
}
// OBS: e.Graphics.FillRectangle(Brushes.Red, NodeBounds(e.Node)); e.Graphics.FillRectangle(Brushes.Red, NodeBounds(e.Node));
é só alterar a parte do Brushes.Brushes
(Ee escolher a cor)...
(Desculpa se estiver meio bagunçado a formatação ainda estou aprendendo a mexer aqui :P)