您的位置:首页 > 其它

treeview 如何改变选中节点的背景。

2016-08-10 22:55 288 查看
http://stackoverflow.com/questions/12886402/how-to-change-background-color-of-selected-node-in-treeview-using-treeviewdrawmo

写的非常好。解决了选中节点的文字前景色问题。 bcjr测试通过。

SolidBrush greenBrush = new SolidBrush(Color.Green);
SolidBrush redBrush = new SolidBrush(Color.Red);

private void myTreeView_drawNode(object sender, DrawTreeNodeEventArgs e)
{
if (e.Node.IsSelected)
{
if (treeView1.Focused)
e.Graphics.FillRectangle(greenBrush, e.Bounds);
else
e.Graphics.FillRectangle(redBrush, e.Bounds);
}
else
e.Graphics.FillRectangle(Brushes.White, e.Bounds);

e.Graphics.DrawRectangle(SystemPens.Control, e.Bounds);

TextRenderer.DrawText(e.Graphics,
e.Node.Text,
e.Node.TreeView.Font,
e.Node.Bounds,
e.Node.ForeColor);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐