删除所选背景(蓝色)

时间:2015-05-26 19:15:08

标签: c# .net windows winforms

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

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

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

1 个答案:

答案 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;
        }
    }
相关问题