Dan Gifford
Dan Gifford

Reputation: 896

Remove selected background (blue)

I'm working with a custom treeview. It has an imageHeight property of 80. Its text is displayed below the node on the screen. Right now, when a node is selected, a blue box appears (https://i.sstatic.net/EmHPh.jpg). I want this box to go away. How do I do this?

My custom treeview code can be found here: http://pastebin.com/UXaJhnA5

Note: the OnPaint event never seems to fire. I'm lost as to why.

Upvotes: 0

Views: 139

Answers (1)

user2131716
user2131716

Reputation:

Set DrawMode property to OwnerDrawText and redraw nodes in DrawNode event


    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;
        }
    }

Upvotes: 1

Related Questions