首页 > 代码库 > [DevExpress]设置FocusedNode的背景色

[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);        }

<style type="text/css">.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }</style>代码效果:

image