Back to Devexpress

How to: Add Images to a Legend

windowsforms-17730-controls-and-libraries-map-control-examples-vector-data-customize-data-appearance-how-to-add-images-to-a-legend.md

latest1.5 KB
Original Source

How to: Add Images to a Legend

  • Nov 13, 2018

This example shows how to use images in a map legend.

The following symbols are used in the example:

|

ColorListLegend.ImageList

|

Gets or sets the source of images to be displayed within a legend.

| |

ColorListLegend.CustomItems

|

Provides access to the collection of custom legend items.

| |

ColorLegendItem

|

An item that stores information about the color and description of the ColorLegendBase class descendants.

| |

ColorLegendItem.ImageIndex

|

Gets or sets the index of an image used by this legend item.

|

csharp
// In the Form's constructor.
//Create a Legend containing images.
ColorListLegend legend = new ColorListLegend();
legend.ImageList = map.ImageList;
legend.CustomItems.Add(
    new ColorLegendItem {
        ImageIndex = 0,
        Text = "Shipwreck"
    });
map.Legends.Add(legend);
vb
' In the Form's constructor.
' Create a Legend containing images.
Dim legend As ColorListLegend = New ColorListLegend()
legend.ImageList = map.ImageList
legend.CustomItems.Add( _
    New ColorLegendItem() With {
        .ImageIndex = 0,
        .Text = "Shipwreck"
    })
map.Legends.Add(legend)