创建组件:ZHTestTreeView
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ZHERP.UI.ZHControl
{
public partial class ZHTestTreeView : TreeView
{
private bool ArrowKeyUp = false;
private bool ArrowKeyDown = false;
private Font foreFont = new Font("微软雅黑", 9F, FontStyle.Regular);
/*1节点被选中 ,TreeView有焦点*/
private SolidBrush brush1 = new SolidBrush(Color.FromArgb(229, 243, 251));//填充颜色
private Pen pen1 = new Pen(Color.FromArgb(102, 167, 232), 1);//边框颜色
/*2节点被选中 ,TreeView没有焦点*/
private SolidBrush brush2 = new SolidBrush(Color.FromArgb(229, 243, 251));
private Pen pen2 = new Pen(Color.FromArgb(222, 222, 222), 1);
/*3 MouseMove的时候 画光标所在的节点的背景*/
private SolidBrush brush3 = new SolidBrush(Color.FromArgb(229, 243, 251));
private Pen pen3 = new Pen(Color.FromArgb(112, 192, 231), 1);
//public const int WM_PRINTCLIENT = 0x0318;
//public const int PRF_CLIENT = 0x00000004;
public ZHTestTreeView()
{
//双缓存防止屏幕抖动
//this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
this.UpdateStyles();
this.DrawMode = TreeViewDrawMode.OwnerDrawAll;
this.FullRowSelect = true;
this.HotTracking = true;
this.HideSelection = false;
this.ShowLines = false;