设为首页 加入收藏

TOP

windform 重绘Treeview "+-"号图标(二)
2019-09-17 16:51:22 】 浏览:38
Tags:windform 重绘 Treeview " -" 图标
gion 3 画节点文本========================================= Rectangle nodeTextRect = new Rectangle( e.Node.Bounds.Left, e.Node.Bounds.Top + 4, e.Node.Bounds.Width + 2, e.Node.Bounds.Height ); nodeTextRect.Width += 4; nodeTextRect.Height -= 4; e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, new SolidBrush(Color.Black), nodeTextRect); //画子节点个数 (111) if (e.Node.GetNodeCount(true) > 0) { e.Graphics.DrawString(string.Format("({0})", e.Node.GetNodeCount(true)), new Font("Arial", 8), Brushes.Gray, nodeTextRect.Right - 4, nodeTextRect.Top -2); } ///*测试用,画文字出现的矩形*/ //if (e.Node.Text != "") // e.Graphics.DrawRectangle(new Pen(Color.Blue), nodeTextRect); #endregion #region 4 画IImageList 中的图标=================================================================== int currt_X = e.Node.Bounds.X; if (this.ImageList != null && this.ImageList.Images.Count > 0) { //图标大小16*16 Rectangle imagebox = new Rectangle( e.Node.Bounds.X - 3 - 16, e.Node.Bounds.Y + 2, 16,//IMAGELIST IMAGE WIDTH 16);//HEIGHT int index = e.Node.ImageIndex; string imagekey = e.Node.ImageKey; if (imagekey != "" && this.ImageList.Images.ContainsKey(imagekey)) e.Graphics.DrawImage(this.ImageList.Images[imagekey], imagebox); else { if (e.Node.ImageIndex < 0) index = 0; else if (index > this.ImageList.Images.Count - 1) index = 0; e.Graphics.DrawImage(this.ImageList.Images[index], imagebox); } currt_X -= 19; /*测试 画IMAGELIST的矩形*/ //if (e.Node.ImageIndex > 0) // e.Graphics.DrawRectangle(new Pen(Color.Black, 1), imagebox); } #endregion } protected override void OnBeforeSelect(TreeViewCancelEventArgs e) { base.OnBeforeSelect(e); if (e.Node != null) { //禁止选中空白项 if (e.Node.Text == "") { //响应上下键 if (ArrowKeyUp) { if (e.Node.PrevNode != null && e.Node.PrevNode.Text != "") this.SelectedNode = e.Node.PrevNode; } if (ArrowKeyDown) { if (e.Node.NextNode != null && e.Node.NextNode.Text != "") this.SelectedNode = e.Node.NextNode; } e.Cancel = true; } } } /// <summary> /// 防止在选择设,treeNode闪屏 /// </summary> protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; if (!DesignMode) { cp.ExStyle |= 0x02000000;// Turn on WS_EX_COMPOSITED } return cp; } } } }

  

 生成后拖动控件到界面中,实际效果如下

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇《C#并发编程经典实例》学习笔记.. 下一篇Asp.Net Core 轻松学-在.Net Core..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目