2010-11-18 63 views

Respuesta

7

Es posible si crea su propia clase TreeView y anula el método OnDrawNode. Por ejemplo, éste destacará nodo seleccionado con el rojo:

class ClassMyTreeView:TreeView 
{ 
    public ClassMyTreeView() 
    { 
     this.DrawMode = TreeViewDrawMode.OwnerDrawText; 
    } 

    protected override void OnDrawNode(DrawTreeNodeEventArgs e) 
    { 
     TreeNodeStates state = e.State; 
     Font font = e.Node.NodeFont ?? e.Node.TreeView.Font; 
     Color fore = e.Node.ForeColor; 
     if (fore == Color.Empty) 
      fore = e.Node.TreeView.ForeColor; 
     if (e.Node == e.Node.TreeView.SelectedNode) 
     { 
      fore = SystemColors.HighlightText; 
      e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds); 
      ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds, fore, Color.Red); 
      TextRenderer.DrawText(e.Graphics, e.Node.Text, font, e.Bounds, fore, Color.Red, TextFormatFlags.GlyphOverhangPadding); 
     } 
     else 
     { 
      e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); 
      TextRenderer.DrawText(e.Graphics, e.Node.Text, font, e.Bounds, fore, TextFormatFlags.GlyphOverhangPadding); 
     } 
    } 
} 
Cuestiones relacionadas