protected override void DrawNodeImageCore(CustomDrawNodeImagesEventArgs e, Rectangle bounds, Point location, object imageList, int imageIndex) { e.Appearance.FillRectangle(e.Cache, bounds); MyTreeListNode node = e.Node as MyTreeListNode; if (node == null) { return; } Image img = node.AvatarImage; if (img != null) { e.Cache.DrawImage(img, node.AvatarImageBounds); } else { e.Cache.DrawRectangle(Pens.Gray, node.AvatarImageBounds); } string caption = node.AvatarCaption; if (caption != string.Empty) { e.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Top; e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; e.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; e.Cache.DrawString(caption, e.Appearance.GetFont(), e.Appearance.GetForeBrush(e.Cache), node.AvatarCaptionBounds, sf); } }
/// <summary> /// 设置图片节点的背景色 /// 说明:在CustomDrawNodeImages事件中使用 /// </summary> /// <param name="tree">TreeList</param> /// <param name="e">CustomDrawNodeImagesEventArgs</param> /// <param name="builderBackColorHandler">委托</param> public static void CustomImageNodeBackColor(this TreeList tree, CustomDrawNodeImagesEventArgs e, Func <TreeListNode, Color> builderBackColorHandler) { TreeListNode _node = e.Node; Color _backColor = builderBackColorHandler(_node); e.Graphics.FillRectangle(new SolidBrush(_backColor), e.Bounds); }
void OnTreeListCustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { TreeList tree = (TreeList)sender; IFileImage _item = (IFileImage)tree.GetRow(e.Node.Id); if (_item.Image == null) { return; } e.Cache.DrawImage(_item.Image, e.SelectImageLocation); e.Handled = true; }
private void treeList1_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { string name = e.Node[0].ToString(); if (name == "Suyama, Michael") { e.SelectImageIndex = 0; // e.SelectImageIndex为图片在ImageList中的index } else { e.SelectImageIndex = 1; } int level = e.Node.Level; if (level == 0) { e.SelectImageIndex = 0; } else if (level == 1) { e.SelectImageIndex = 1; } else if (level == 2) { e.SelectImageIndex = 2; } else if (level == 3) { e.SelectImageIndex = 3; } else if (level == 4) { e.SelectImageIndex = 4; } else if (level == 5) { e.SelectImageIndex = 5; } else if (level == 6) { e.SelectImageIndex = 6; } else if (level == 7) { e.SelectImageIndex = 7; } }
/// <summary> /// 树形控件添加图标 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void treeList_Station_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { //0 叶子 1 打开文件夹 2 文件夹 if (e.Node.Nodes.Count > 0) { if (e.Node.Expanded) { e.SelectImageIndex = 1; return; } e.SelectImageIndex = 2; } else { e.SelectImageIndex = 0; } }
private void treeListEmp_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { //if (e.Node.HasChildren) // if (e.Node.Expanded) // e.SelectImageIndex = 0; // else // e.SelectImageIndex = 1; if (e.Node.HasChildren) { e.Node.SelectImageIndex = 0; e.Node.ImageIndex = 0; } else { e.Node.SelectImageIndex = 1; e.Node.ImageIndex = 1; } }
private void treeListTask_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { foreach (TreeListNode treeListNode in e.Node.Nodes) { // ImageIndex用来指定树节点在正常状态下显示的图标, // SelectImageIndex用来指定树节点在选中状态下显示的图标 if (Convert.ToInt32(treeListNode["Status"].ToString()) == 0) { treeListNode.ImageIndex = 0; treeListNode.SelectImageIndex = 0; } else { treeListNode.ImageIndex = 1; treeListNode.SelectImageIndex = 2; } } }
private void treeList1_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) { //DrawBackGround(e.Node, e); }