当用户焦点离开TreeView时,TreeView选中节点仍然高亮,但是颜色符合主题。

设置TreeView.HideSelection = False;可让选中节点保持高亮。

添加重绘事件

TreeView.DrawMode = TreeViewDrawMode.OwnerDrawText;

TreeView.DrawNode += new DrawTreeNodeEventHandler(TreeView_DrawNode);

// Draws a node.
private void TreeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
// Draw the background and node text for a selected node.
if ((e.State & TreeNodeStates.Selected) != )
{
// Draw the background of the selected node. The NodeBounds
// method makes the highlight rectangle large enough to
// include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node));
// Retrieve the node font. If the node font has not been set,
// use the TreeView font.
Font nodeFont = e.Node.NodeFont;
if (nodeFont == null)
nodeFont = ((TreeView)sender).Font;
// Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White,
Rectangle.Inflate(e.Bounds, , ));
}
// Use the default background and node text.
else
{
e.DrawDefault = true;
}
// If a node tag is present, draw its string representation
// to the right of the label text.
if (e.Node.Tag != null)
{
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, Brushes.Yellow, e.Bounds.Right + , e.Bounds.Top);
}
// If the node has focus, draw the focus rectangle large, making
// it large enough to include the text of the node tag, if present.
if ((e.State & TreeNodeStates.Focused) != )
{
using (Pen focusPen = new Pen(Color.Black))
{
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
Rectangle focusBounds = NodeBounds(e.Node);
focusBounds.Size = new Size(focusBounds.Width - , focusBounds.Height - );
e.Graphics.DrawRectangle(focusPen, focusBounds);
}
}
}

WinForm TreeView节点重绘,失去焦点的高亮显示的更多相关文章

  1. C#TreeView节点选中后失去焦点时改变节点背景色

    C#TreeView节点选中后失去焦点时改变节点背景色 在使用TreeView控件时候,单击一个节点,当鼠标聚焦到别的地方的时候,之前点击的这个节点就看不清楚了 举例截图 单击后           ...

  2. WPF如何实现TreeView节点重命名

    我们经常看到一些软件比如酷狗音乐,在对列表右键进行重命名的时候,当前列表会泛白并且进入可编辑状态,当我们更改完成后就会并进入非编辑状态,这些具体是怎么实现的呢?下面的方法也许会提供一些思路,下面的Tr ...

  3. WPF 之 TreeView节点重命名

    下面的TreeView节点是通过数据双向绑定的方式,绑定到TextBlock控件和TextBox控件的Text属性上,并且让两者绑定相同的属性,同时使TextBox控件刚好完全覆盖TextBlock控 ...

  4. WinForm中的重绘 - 按钮等控件的背景渐变色重绘

    注:brush通过起止坐标来控制重绘范围及方向.比如从上到下渐变时,brush第二个Point参数是左下角坐标. private void PaintGradientBackground(Button ...

  5. Winform TreeView 节点拖动

    private void treeView_ItemDrag(object sender, ItemDragEventArgs e) { TreeNode dragNode = e.Item as T ...

  6. winform TreeView 节点选择

    public partial class Form1 : Form { public Form1() { InitializeComponent(); } string tag = "Tru ...

  7. Winform解决界面重绘闪烁的问题

    在窗体或用户控件中重写CreateParams protected override CreateParams CreateParams { get { CreateParams cp = base. ...

  8. WinForm中的重绘 - 文本的重绘

    两种方式 TextRenderer.DrawText 注意:默认在每次绘制的文本左右有padding,即使参数中设置了TextFormatFlags.NoPadding也是一样,因此在分段绘制文本时( ...

  9. 重绘和回流(reflow和repaint)

    由于DOM操作会导致浏览器的回流,回流需要花费大量的时间进行样式计算和节点重绘与渲染,所以应当尽量减少回流次数. 以下是几种常见的减少重绘和回流的方法: 一.不要一项一项的更改页面的样式,尽量一口气写 ...

随机推荐

  1. Linux上安装Mysql+Apache+Php

    一.安装Mysql 1.卸载默认的mysql yum -y remove mysql-libs-* Removed:  mysql-libs.x86_64 0:5.1.73-3.el6_5 卸载成功 ...

  2. 【开源项目8】Android开源项目分类汇总【畜生级别】

    欢迎大家推荐好的Android开源项目,可直接Commit或在 收集&提交页 中告诉我,欢迎Star.Fork :) 微博:Trinea    主页:www.trinea.cn    邮箱:t ...

  3. mysql模糊查询 like/REGEXP

    原文:mysql模糊查询like/REGEXP 增删改查是mysql最基本的功能,而其中查是最频繁的操作,模糊查找是查询中非常常见的操作,于是模糊查找成了必修课. like模式 like意思是长得像, ...

  4. MS SQL SERVER 中的系统表

    MS SQL SERVER 中的系统表 序号 名称 说明 备注 1 syscolumns 每个表和视图中的每列在表中占一行,存储过程中的每个参数在表中也占一行.   2 syscomments 包含每 ...

  5. TaskUtil多线程与定时任务

    package com.taoban.util; /**  * 执行单次任务或定时任务工具类(用于减少new Thread()和new Timer()的使用)  */ public class Tas ...

  6. 剑指Offer30 从1到n整数出现1的个数

    /************************************************************************* > File Name: 30_NumerO ...

  7. Linux 网卡设备驱动程序设计(3)

    三.网络子系统深度分析 用户程序通过网络发送这个网络数据包 通过 SCI 协议无关接口 协议栈 <   UDP的实现  会选择路由 <    IP的实现  会建立这个邻居子系统,建立邻居信 ...

  8. 【转载】TalkingData首席金融行业专家鲍忠铁:18亿数据解读移动互联网

    http://www.36dsj.com/archives/33417 鲍忠铁:大家下午好! 今天我会讲三个议题,一是用18亿数据解读现在移动互联网的生态圈.二是看看数据有什么样的应用.三是大数据的隐 ...

  9. Linux 系统中用户切换(su user与 su - user 的区别)

    1. Linux系统中用户切换的命令为su,语法为: su [-fmp] [-c command] [-s shell] [--help] [--version] [-] [USER [ARG]] 参 ...

  10. cocos2d-x 创建工程详解

    我们的编写的第一个程序一般习惯上都命名为HelloWorld,从它开始再学习其他的内容.下面介绍的第一个Cocos2d-x游戏我们也命名为HelloWorld. 创建工程 在Cocos2d-x早期版本 ...