DevExpress TreeList树组件自定义TreeListNode的Tooltip的方法(自动消息提示)
作者:作者不详  发布日期:2021-07-28 19:44:25
  DevExpress TreeList树组件自定义TreeListNode的Tooltip的方法(自动消息提示)

DevExpress TreeList树组件自定义TreeListNode的Tooltip的方法(自动消息提示)


本文实例展示了DevExpress实现自定义TreeListNode的Tooltip的方法。


TreeListNode的Tooltip效果:


贴图图片-treelist节点提示


贴图图片-treelist节点提示1



解决方案:

1.设置treeList的ToolTipController属性,绑定toolTipController1。

2.实现toolTipController1的GetActiveObjectInfo事件。


toolTipController1 控件属性设置:


贴图图片-treelist节点提示2




C# Code:


public static class TreeListExtension
{
  
  
/// </summary>
  
/// <param name="tree">TreeList</param>
  
/// <param name="e">ToolTipControllerGetActiveObjectInfoEventArgs</param>
  
/// <param name="builderNodeTooltipHandler">委托</param>
  
public static void CustomNodeTooltip(this TreeList tree, ToolTipControllerGetActiveObjectInfoEventArgs e, Func<TreeListNode, string> builderNodeTooltipHandler)
  {
    
if (e.SelectedControl is DevExpress.XtraTreeList.TreeList)
    {
      TreeListHitInfo _hit
= tree.CalcHitInfo(e.ControlMousePosition);
      
if (_hit.HitInfoType == HitInfoType.Cell)
      {
        TreeListViewInfo _viewInfo
= tree.ViewInfo;
        RowInfo _rowInfo
= _viewInfo.GetRowInfoByPoint(e.ControlMousePosition);
        CellInfo _cellInfo
= _rowInfo.Cells[_hit.Column.VisibleIndex] as CellInfo;
        EditHitInfo _editHitInfo
= _cellInfo.EditorViewInfo.CalcHitInfo(e.ControlMousePosition);
        
if (_editHitInfo.HitTest == EditHitTest.MaskBox)
        {
          
string _toolTip = builderNodeTooltipHandler(_hit.Node);
          
if (!string.IsNullOrEmpty(_toolTip))
          e.Info
= new ToolTipControlInfo(_cellInfo, _toolTip);
        }
      }
    }
  }
  
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




toolTipController1_GetActiveObjectInfo事件:


C# Code:


private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
  tlGroup4User.CustomNodeTooltip(e, node
=>
  {
    toolTipController1.ImageIndex
= node.ImageIndex;
    
    NodeModel m
= node.Tag as NodeModel;
    
if (m.Type.ToUpper() == "GROUP")
    {
      
return $"部门编号:{m.DataID}\r\n部门名称:{m.Text}";
    }
    
else
    {
      
return $"员工编号:{m.DataID}\r\n员工姓名:{m.Text}";
    }
    });
    
  }
  
  
//来源:C/S框架网 | www.csframework.com | QQ:23404761





C/S框架网|原创精神.创造价值.打造精品


扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务


上一篇 下一篇