WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色
2016-03-30 17:51
337 查看
在B/S开发中,对TreeView控件要改变当前选中节点的颜色比较方便,其有相应的SelectedNodeChanged事件进行控制,但对于WinForm则没有这样方便。申明一下,我在这儿所说的改变当前节点的字体与颜色,主要是在WinForm中的TreeView控件,当前选中节点后,其失去鼠标焦点后节点的字体与颜色失去了选中状态,层级一多,我们就不知道当前选择的是那个节点了。用户体验性稍微欠缺一些。其实实现方法非常简单,主要用到TreeView的两个事件,分别为:BeforeSelect与AfterSelect事件。代码如下:
TreeNode theLastNode = null;//最后选择的节点(用于还原节点状态)
private void tvCustomerClass_AfterSelect(object sender, TreeViewEventArgs e)
{
if (this.tvCustomerClass.SelectedNode != null)
{
theLastNode = tvCustomerClass.SelectedNode;
}
}
private void tvCustomerClass_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
e.Node.ForeColor = Color.Blue;
e.Node.NodeFont = new Font(“宋体“, 10, FontStyle.Underline|FontStyle.Bold);
if (theLastNode != null)
{
theLastNode.ForeColor = SystemColors.WindowText;
theLastNode.NodeFont = new Font(“宋体“, 11, FontStyle.Regular);
}
}
TreeNode theLastNode = null;//最后选择的节点(用于还原节点状态)
private void tvCustomerClass_AfterSelect(object sender, TreeViewEventArgs e)
{
if (this.tvCustomerClass.SelectedNode != null)
{
theLastNode = tvCustomerClass.SelectedNode;
}
}
private void tvCustomerClass_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
e.Node.ForeColor = Color.Blue;
e.Node.NodeFont = new Font(“宋体“, 10, FontStyle.Underline|FontStyle.Bold);
if (theLastNode != null)
{
theLastNode.ForeColor = SystemColors.WindowText;
theLastNode.NodeFont = new Font(“宋体“, 11, FontStyle.Regular);
}
}
相关文章推荐
- Tomcat7.0源码分析——类加载体系
- {head first} --- networking 2
- 《数据结构》 队列(Queue)操作代码集合
- android密度
- hdu 2073 无限的路
- AngularJS 应用入门
- 常见面试题总结
- 常见面试题总结
- iOS自定义工具栏(Toolbar)
- WinPcap权威指南(三):ARP协议
- 大众点评cat系统的搭建笔记
- chrome扩展——Postman
- 【BZOJ3450】Tyvj1952 Easy【期望DP】
- Spring MVC 结合EL 表达式 一种传参的简单方式
- Java中的泛型理解(转)
- LeetCode 217 Contains Duplicate
- 程序员必备:100本免费编程图书以及整理IT网站
- 准备写一个新的架构
- Joomla,wordpress,Drupal,DedeCms开源程序比较
- Android Service生命周期及用法!