c#DevExpress组件TreeList控件自己控制节点图标(一)

TreeList控件的节点图标设置,在显示属性里要么设置为全部显示,要么全部不显示。

当前项目需求为,个别节点设置为不可用,个别节点设置为只显示线不显示选择框,由此只能抛弃treelist自身的checkbox显示设置,自己画图标。

利用StateImage属性设置图标显示,首先做一个图标的枚举,从资源文件里读取:

/// <summary>
    /// TreeList页节点选择状态
    /// </summary>
    public enum TreeNodeCheckImage
    {
        CheckedBranch = 0,  //选中枝
        UnCheckedBranch = 1,//未选中枝
        CheckedLeaf = 2,    //选中叶(暂不用,跟0一样)
        UnCheckedLeaf = 3,  //未选中叶(暂不用,跟1一样)
        BranchLine = 4,     //枝线
        LeafLine = 5,       //叶线
        DisCheckedBranch = 6,//不让选中枝
        DisCheckedLeaf = 7,//不让选中叶
        Loading = 8
    }

    /// <summary>
    /// TreeList节点图标
    /// </summary>
    public class TreeListImageState
    {
        /// <summary>
        /// 自定义TreeList节点图标
        /// </summary>
        /// <returns></returns>
        public static ImageList GetImageList()
        {
            ImageList treeListImageList = new ImageList();
            treeListImageList.TransparentColor = System.Drawing.Color.Transparent;
            treeListImageList.Images.Add("0", OrgCertificate.Properties.Resources.tree_CheckedBranch);
            treeListImageList.Images.Add("1", OrgCertificate.Properties.Resources.tree_UnCheckedBranch);
            treeListImageList.Images.Add("2", OrgCertificate.Properties.Resources.tree_CheckedLeaf);
            treeListImageList.Images.Add("3", OrgCertificate.Properties.Resources.tree_UnCheckedLeaf);
            treeListImageList.Images.Add("4", OrgCertificate.Properties.Resources.tree_BranchLine);
            treeListImageList.Images.Add("5", OrgCertificate.Properties.Resources.tree_LeafLine);
            treeListImageList.Images.Add("6", OrgCertificate.Properties.Resources.tree_DisCheckedBranch);
            treeListImageList.Images.Add("7", OrgCertificate.Properties.Resources.tree_DisCheckedLeaf);
            treeListImageList.Images.Add("8", OrgCertificate.Properties.Resources.tree_Loading);
            treeListImageList.ImageSize = new System.Drawing.Size(20, 20);
            return treeListImageList;
        }

        /// <summary>
        /// 自定义TreeList节点图标
        /// </summary>
        /// <returns></returns>
        public static ImageCollection GetImageCollection()
        {
            ImageCollection treeListImageCol = new ImageCollection();
            treeListImageCol.TransparentColor = System.Drawing.Color.Transparent;
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_CheckedBranch, "0");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_UnCheckedBranch, "1");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_CheckedLeaf, "2");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_UnCheckedLeaf, "3");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_BranchLine, "4");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_LeafLine, "5");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_DisCheckedBranch, "6");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_DisCheckedLeaf, "7");
            treeListImageCol.Images.Add(OrgCertificate.Properties.Resources.tree_Loading, "8");
            treeListImageCol.ImageSize = new System.Drawing.Size(20, 20);
            return treeListImageCol;
        }

    }
}


 

你可能感兴趣的:(c#DevExpress组件TreeList控件自己控制节点图标(一))