Winform中Treeview控制項失去焦點,將選擇的節點設置為高亮顯示 (2012-07-16 13:47:07)轉載▼標簽: winform treeview drawnode Treeview控制項--Name:tVtypeList將tVtypeList的HideSelection屬性設置為Fa ...
Winform中Treeview控制項失去焦點,將選擇的節點設置為高亮顯示 (2012-07-16 13:47:07)轉載▼
標簽: winform treeview drawnode
Treeview控制項--Name:tVtypeList
將tVtypeList的HideSelection屬性設置為False,DrawMode屬性設置為OwnerDrawText
將tVtypeList的DrawNode事件寫為:
private void tVtypeList_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.FillRectangle(Brushes.White, e.Node.Bounds);
if (e.State == TreeNodeStates.Selected)//做判斷
{
e.Graphics.FillRectangle(Brushes.Blue, new Rectangle(e.Node.Bounds.Left, e.Node.Bounds.Top, e.Node.Bounds.Width, e.Node.Bounds.Height));//背景色為藍色
e.Graphics.DrawString(e.Node.Text, tVtypeList.Font, Brushes.White, e.Bounds);
//字體為白色
}
else
{
e.DrawDefault = true;
}
}
分享: