本文实例讲述了DevExpress设置FocusedNode背景色的方法,很实用的功能,具体实现方法如下:
主要功能代码如下:
/// <summary>/// 设置FocusedNode的背景色/// 说明:/// 在CustomDrawNodeCell事件中使用/// 示例:/// _curTree.SetFocusedNodeBackColor(Color.Green, Color.PeachPuff, Color.Black, e);/// </summary>/// <param name="tree">TreeList</param>/// <param name="backColor1">起始背景颜色</param>/// <param name="backColor2">结束背景颜色</param>/// <param name="foreBrush">字体颜色</param>/// <param name="e">CustomDrawNodeCellEventArgs</param>public static void SetFocusedNodeBackColor(this TreeList tree, Color backColor1, Color backColor2, Color foreBrush, CustomDrawNodeCellEventArgs e){ if (e.Node == tree.FocusedNode) { Brush _backBrush, _foreBrush; _backBrush = new LinearGradientBrush(e.Bounds, backColor1, backColor2, LinearGradientMode.Horizontal); _foreBrush = new SolidBrush(foreBrush); e.Graphics.FillRectangle(_backBrush, e.Bounds); e.Graphics.DrawString(e.CellText, e.Appearance.Font, _foreBrush, e.Bounds, e.Appearance.GetStringFormat()); e.Handled = true; }}
代码使用:
private void tlLHData_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e){ TreeList _curTree = sender as TreeList; _curTree.SetFocusedNodeBackColor(Color.Orange, Color.PeachPuff, Color.Black, e);}
运行效果如下:
新闻热点
疑难解答