C#中TreeView节点的自定义绘制方法
程序员文章站
2023-12-11 20:24:16
本文实例讲述了c#中treeview节点的自定义绘制方法。分享给大家供大家参考。具体如下:
if ((e.state & treenodestates.selec...
本文实例讲述了c#中treeview节点的自定义绘制方法。分享给大家供大家参考。具体如下:
if ((e.state & treenodestates.selected) != 0) { //演示为绿底白字 e.graphics.fillrectangle(brushes.deepskyblue, e.node.bounds); font nodefont = e.node.nodefont; if (nodefont == null) nodefont = ((treeview)sender).font; e.graphics.drawstring(e.node.text, nodefont, brushes.white, rectangle.inflate(e.bounds, 2, 0)); } else { e.drawdefault = true; } if ((e.state & treenodestates.focused) != 0) { using (pen focuspen = new pen(color.black)) { focuspen.dashstyle = system.drawing.drawing2d.dashstyle.dot; rectangle focusbounds = e.node.bounds; focusbounds.size = new size(focusbounds.width - 1, focusbounds.height - 1); e.graphics.drawrectangle(focuspen, focusbounds); } }
希望本文所述对大家的c#程序设计有所帮助。