WinForm TreeView节点重绘,失去焦点的高亮显示
当用户焦点离开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节点重绘,失去焦点的高亮显示的更多相关文章
- C#TreeView节点选中后失去焦点时改变节点背景色
C#TreeView节点选中后失去焦点时改变节点背景色 在使用TreeView控件时候,单击一个节点,当鼠标聚焦到别的地方的时候,之前点击的这个节点就看不清楚了 举例截图 单击后 ...
- WPF如何实现TreeView节点重命名
我们经常看到一些软件比如酷狗音乐,在对列表右键进行重命名的时候,当前列表会泛白并且进入可编辑状态,当我们更改完成后就会并进入非编辑状态,这些具体是怎么实现的呢?下面的方法也许会提供一些思路,下面的Tr ...
- WPF 之 TreeView节点重命名
下面的TreeView节点是通过数据双向绑定的方式,绑定到TextBlock控件和TextBox控件的Text属性上,并且让两者绑定相同的属性,同时使TextBox控件刚好完全覆盖TextBlock控 ...
- WinForm中的重绘 - 按钮等控件的背景渐变色重绘
注:brush通过起止坐标来控制重绘范围及方向.比如从上到下渐变时,brush第二个Point参数是左下角坐标. private void PaintGradientBackground(Button ...
- Winform TreeView 节点拖动
private void treeView_ItemDrag(object sender, ItemDragEventArgs e) { TreeNode dragNode = e.Item as T ...
- winform TreeView 节点选择
public partial class Form1 : Form { public Form1() { InitializeComponent(); } string tag = "Tru ...
- Winform解决界面重绘闪烁的问题
在窗体或用户控件中重写CreateParams protected override CreateParams CreateParams { get { CreateParams cp = base. ...
- WinForm中的重绘 - 文本的重绘
两种方式 TextRenderer.DrawText 注意:默认在每次绘制的文本左右有padding,即使参数中设置了TextFormatFlags.NoPadding也是一样,因此在分段绘制文本时( ...
- 重绘和回流(reflow和repaint)
由于DOM操作会导致浏览器的回流,回流需要花费大量的时间进行样式计算和节点重绘与渲染,所以应当尽量减少回流次数. 以下是几种常见的减少重绘和回流的方法: 一.不要一项一项的更改页面的样式,尽量一口气写 ...
随机推荐
- SQL VS NoSQL 如何选择数据库
在前一篇文章中我们主要的讨论了SQL与NoSQL数据库之间的主要的差别.接下来,我们将会利用上一篇中的知识来确定在特定的场景中如何确定比较好的选择. 首先我们先来总结一下: SQL数据库: 使用表存 ...
- 如何使用nodejs发邮件
昨天就开始想使用nodemailer来实现一个发送邮件的功能,不过发现了很多个坑,网上给的资料也很杂很乱,所以决定写一篇真正能用的来帮助大家减少弯路 首先,我们先来看下代码,如上所示. 步骤: 1.下 ...
- Xamarin自学教程(Android)之一
废话少说,我们直接开始吧.有兴趣的就一起,我慢慢写,咱们一起慢慢学.希望两个月内能基本完成基于Xamarin的Android开发内容. 还是一样,先来安装开发环境吧.跟着做就行了. 首先,我们到微软的 ...
- C# struct
很困惑,为什么C#会有struct 这样一个关键字.虽然我用C#几年了,但绝少用到此关键字.我在相关书籍上学习C#的时候,看到过struct内容——但C#并不是我的第一入门语言,所以没有那么细致的学习 ...
- 剑指Offer24 复杂链表的复制
/************************************************************************* > File Name: 24_Comple ...
- 递归小Demo
public class demo5 { public static void main(String[] args) { //初始值为100 int n = 100; ...
- @@Error使用简单小结
使用中经常用到@@Error来判断上一个语句是否执行成功,对此小结一下,可能有些不准确,欢迎指出. 1.1 介绍 SQL SERVER 中@@表示系统全局变量 (1) 返回执行的上一个 Tran ...
- 每天一道LeetCode--371. Sum of Two Integers
alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...
- MySQL Server 5.5安装中遇到的问题及解决方法
之前开始用师兄用过的电脑工作,各种不适应,开始重新搭建自己习惯的环境,重装MySQL就是其中一项,然后重装过程中遇到了问题,具体情况总结如下: 1.以前也重新安装过MySQL,但是完全没有用过就直接卸 ...
- apache Internal Server Error 的几个问题
Internal Server Error The server encountered an internal error or misconfiguration and was unable to ...