2015-05-26 69 views
0

我正在使用自定义树视图。它具有80的imageHeight属性。其文本显示在屏幕上的节点下方。现在,当选择一个节点时,会出现一个蓝色框(http://imgur.com/V6hlPYs)。 我想让这个盒子消失。我该怎么做呢?删除选定的背景(蓝色)

我的自定义代码树视图可以在这里找到: http://pastebin.com/UXaJhnA5

注:OnPaint事件似乎永远不会触发。我失去了为什么。

+0

你是不是绘制背景都没有。所以你得到默认的一个,蓝色的选定节点。请注意在[MSDN示例代码](https://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode%28v=vs.110)中使用e.Graphics.FillRectangle() %29.aspx)。 –

+0

如何结束没有突出显示的背景? –

回答

1

设置DrawMode属性OwnerDrawText和重绘DrawNode节点事件


private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e) 
    { 
     if ((e.State & TreeNodeStates.Selected) != 0) 
     { 
      e.Graphics.FillRectangle(Brushes.White, e.Node.Bounds); 

      Font nodeFont = e.Node.NodeFont; 
      if (nodeFont == null) nodeFont = ((TreeView)sender).Font; 
      nodeFont = new Font(nodeFont.FontFamily, nodeFont.Size, FontStyle.Bold|FontStyle.Italic); 

      e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.Black, 
       Rectangle.Inflate(e.Bounds, -2, -2)); 
     } 
     else 
     { 
      e.DrawDefault = true; 
     } 
    } 
+0

非常感谢。您的回答为我们的团队提供了我们需要的所有功能以增强主要功能! –