Exferia/Exferia_Controles/Exferia_Controles/Exferia_TreeView.cs

62 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Exferia_Controles
{
public partial class Exferia_TreeView : TreeView
{
public Exferia_TreeView()
{
InitializeComponent();
this.DrawMode = TreeViewDrawMode.OwnerDrawText;
}
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{
//TreeNodeStates state = e.State;
//Fuente
Font fnt_Fuente = e.Node.NodeFont ?? e.Node.TreeView.Font;
Color clt_Color_Fuente = e.Node.ForeColor;
if (clt_Color_Fuente == Color.Empty)
clt_Color_Fuente = e.Node.TreeView.ForeColor;
//Fondo
Color clt_Color_Fondo = e.Node.BackColor;
//Dimensiones
int int_X = e.Bounds.X;
int int_Y = e.Bounds.Y;
int int_Ancho = e.Bounds.Width;
int int_Alto = e.Bounds.Height;
//Seleccionado
if (e.Node == e.Node.TreeView.SelectedNode)
{
e.Graphics.DrawRectangle(new Pen(Color.Red), int_X, int_Y, int_Ancho-1, int_Alto-1);
e.Graphics.FillRectangle(new SolidBrush(clt_Color_Fondo), int_X+1, int_Y+1, int_Ancho-2, int_Alto-2);
Point pt_Texto = new Point(int_X, int_Y + 1);
TextRenderer.DrawText(e.Graphics, e.Node.Text, fnt_Fuente, pt_Texto, clt_Color_Fuente, clt_Color_Fondo, TextFormatFlags.GlyphOverhangPadding);
}
//Normal
else
{
e.Graphics.DrawRectangle(new Pen(clt_Color_Fondo), int_X, int_Y, int_Ancho, int_Alto);
e.Graphics.FillRectangle(new SolidBrush(clt_Color_Fondo), int_X, int_Y, int_Ancho, int_Alto);
TextRenderer.DrawText(e.Graphics, e.Node.Text, fnt_Fuente, e.Bounds, clt_Color_Fuente, TextFormatFlags.GlyphOverhangPadding);
}
}
}
}