DevExpress TreeList树组件自定义TreeListNode的Tooltip的方法(自动消息提示)
DevExpress TreeList树组件自定义TreeListNode的Tooltip的方法(自动消息提示)
扫一扫加作者微信
本文实例展示了DevExpress实现自定义TreeListNode的Tooltip的方法。
TreeListNode的Tooltip效果:
解决方案:
1.设置treeList的ToolTipController属性,绑定toolTipController1。
2.实现toolTipController1的GetActiveObjectInfo事件。
toolTipController1 控件属性设置:
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
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
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
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网