1. 程式人生 > >c#中winform方式中給treeview節點加圖片

c#中winform方式中給treeview節點加圖片

1  在form中增加一個imagelist

2 設定treeview的imagelist屬性

3 程式碼如下

private void treeView1_AfterCollapse(object sender, TreeViewEventArgs e)
        {
            if (e.Node == treeView1.Nodes[0])
            {
                return;
            }
            e.Node.SelectedImageIndex = 1;
            e.Node.ImageIndex = 1;
        }

        private void treeView1_AfterExpand(object sender, TreeViewEventArgs e)
        {
            if (e.Node == treeView1.Nodes[0])
            {
                return;
            }
            e.Node.SelectedImageIndex = 2;
            e.Node.ImageIndex = 2;
        }