Treeview 丢失焦点后依然高亮 SelectedNode

参考:StackOverFlowControl.Validating 事件

注意 TreeView 的 HideSelection 要保持为默认值True

 
private TreeNode previousSelectedNode;

private void treeView1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
    treeView1.SelectedNode.BackColor = SystemColors.Highlight;
    treeView1.SelectedNode.ForeColor = Color.White;
    previousSelectedNode = treeView1.SelectedNode;
}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
    if(previousSelectedNode != null)
    {
        previousSelectedNode.BackColor = treeView1.BackColor;
        previousSelectedNode.ForeColor = treeView1.ForeColor;
    }
}

 

posted @ 2017-08-05 20:44  只追昭熙  阅读(1014)  评论(0编辑  收藏  举报