Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

windows - C# How do I change the treeview selected background color but with the image?

So I have a tree list that has these 2 nodes in them. This is the image and all it is is 2 tree nodes that look normal with am image. But when I select one I have code to chang the background but this is what happend. The background has changed and everything but the image has gone away. I was wondering if there was any way to change the background but still have the image? This is the code I got and it works but it could be a little better.

private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
    {
        var i = e.Bounds;
        i.Width = 1000;
        i.X = -100;
        if (e.Node.IsSelected)
        {
            if (treeView1.Focused)
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(233, 236, 244)), i);
        }
        else
            e.Graphics.FillRectangle(Brushes.Transparent, i);

        TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.TreeView.Font, e.Node.Bounds,  e.Node.ForeColor);
    }
question from:https://stackoverflow.com/questions/65648602/c-sharp-how-do-i-change-the-treeview-selected-background-color-but-with-the-imag

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...