winforms

What is a StateImage in a TreeView?


I have recently discovered this answer which allows me to identify if a user has clicked on a node or not. The TreeViewHitTestInfo returned by the HitTest() method contains a Location field of type TreeViewHitTestLocations with the following flags:

public enum TreeViewHitTestLocations
{
    None = 1,
    Image = 2,
    Label = 4,
    Indent = 8,
    PlusMinus = 16,
    RightOfLabel = 32,
    StateImage = 64,
    AboveClientArea = 256,
    BelowClientArea = 512,
    RightOfClientArea = 1024,
    LeftOfClientArea = 2048,
}

This is what I found through testing:

Screenshot

None:         White
Image:        Green
Label:        Yellow
Indent:       Dark blue
PlusMinus:    Red
RightOfLabel: Light blue

The ClientArea flags are in light gray, but I haven't been able to identify the StateImage one. What is a StateImage?


Solution

  • As @Hans Passant mentioned in the comments: you need to set the StateImageList property to render the StateImage areas.