Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change my treeView icons insted of +,- like a windows explorer treeview in c#.net win forms [duplicate]

How can I change the expand/collapse images from the plus ( + ) and minus ( - ) images that appear when ShowPlusMinus and/or ShowRootLines are true.

To help visualize, I would like to make the following TreeView treeview plus/minus +/-

Look like this (like Windows explorer)

treeview arrows

like image 252
user1858718 Avatar asked Dec 05 '22 13:12

user1858718


1 Answers

Expanding on Ivan Ičin's solution :

[DllImport("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
private static extern int SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);

public static void SetTreeViewTheme(IntPtr treeHandle) {
     SetWindowTheme(treeHandle, "explorer", null);
}

To use, add a TreeView to your form, and in Form_Load :

SetTreeViewTheme( treeView1.Handle );

Alternatively, you can extend the TreeView object

public class MyTreeView : TreeView
{

    [DllImport("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
    private static extern int SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);

    public MyTreeView() {
        SetWindowTheme(this.Handle, "explorer", null);
    }
}

before and after treeview Depicts what it looks like before and after calling SetWindowTheme

like image 140
Kraang Prime Avatar answered Feb 23 '23 00:02

Kraang Prime