TreeView节点自定义绘制样式

TreeView节点自定义绘制样式

2023年6月22日发(作者:)

TreeView节点⾃定义绘制样式TreeView节点⾃定义绘制需要设置属性DrawMode属性为OwnerDrawAll; public LTreeNew() { // This call is required by the Form Designer. UI(this, InitializeComponent);

// TODO: Add any initialization after the InitForm call //⾃已绘制

de = rawAll; de += new DrawTreeNodeEventHandler(tree1_DrawNode); } //在绘制节点事件中,按⾃已想的绘制

private void tree1_DrawNode(object sender, DrawTreeNodeEventArgs e) { eNodeDraw(sender, e, imageCollectionTree, , 0, 0, 1); }

///

/// 调整TreeView 样式 /// /// /// /// 节点图⽚组件 /// 总宽度 /// 展开图 /// 收缩图 /// 叶⼦图 public static void SetTreeNodeDraw(object sender, DrawTreeNodeEventArgs e, ImageCollection imageList1, int Width, int ExpandImageIndex, int CollapseImageIndex, int LeafImageIndex) { TreeNode tn = as TreeNode; if (tn == null) { return; } Point ptbigimage = new Point(.X - 5, .Y + 5); Point ptsmallimage = new Point(.X-5, .Y + 5); Size szbig = new Size(16, 16);//打开收缩图⽚ Size szsmall = new Size(16, 16);//叶⼦图⽚ //Rectangle bcimage = new Rectangle(ptimage, new Size(33, 23)); //根据节点增加图⽚ if (nded) { age([ExpandImageIndex], new Rectangle(ptbigimage, szbig)); } else if ( > 0) { age([CollapseImageIndex], new Rectangle(ptbigimage, szbig)); } else { age([LeafImageIndex], new Rectangle(ptsmallimage, szsmall)); } //增加背景颜⾊ Point pt = new Point(.X + 11, .Y); Brush bccolor = new SolidBrush(gb(((int)(((byte)(224)))), ((int)(((byte)(229)))), ((int)(((byte)(242)))))); Brush ybccolor = new SolidBrush(gb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))))); Rectangle bcrt = new Rectangle(pt, new Size(Width - .X, ));//使⽤Width充满整⾏ if (( & d) != 0) { ctangle(bccolor, bcrt); } else { ctangle(ybccolor, bcrt); } //增加格线 using (Pen focusPen = new Pen(gb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))))) { yle = ; ctangle(focusPen, bcrt); } //设置⽂本颜⾊和字体 Point ptft = new Point(.X + 16, .Y + 7); Rectangle rt = new Rectangle(ptft, new Size(, )); Brush bfcolor = new SolidBrush(gb(((int)(((byte)(59)))), ((int)(((byte)(59)))), ((int)(((byte)(59)))))); Font nf = nt == null ? ((TreeView)sender).Font : nt; ring(, nf, bfcolor, e(rt, 1, 4)); }另外,ItemHeight属性调整节点显⽰⾼度;FullRowSelect和ShowLines属性设置选中整⾏。

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687382280a5886.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信