1 private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
2 {
3 e.DrawDefault = true;//由操作系统绘制节点,默认值为false
4 }
1 private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
2 {
3 if ((e.State & TreeNodeStates.Selected) != 0)
4 {
5 e.Graphics.FillRectangle(Brushes.DodgerBlue, e.Node.Bounds);
6
7 Font nodeFont = e.Node.NodeFont;
8 if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
9 e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
10 }
11 else
12 {
13 e.DrawDefault = true;
14 }
15
16 if ((e.State & TreeNodeStates.Focused) != 0)
17 {
18 using (Pen focusPen = new Pen(Color.White))
19 {
20 focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
21 Rectangle focusBounds = e.Node.Bounds;
22 focusBounds.Size = new Size(focusBounds.Width - 1,
23 focusBounds.Height - 1);
24 e.Graphics.DrawRectangle(focusPen, focusBounds);
25 }
26 }
27 }