This example demonstrates how to select labels on the map by handling SelectBoxFinal event of the map control. Here is a screenshot with the results of the code execution.

using System.IO;
using System.Linq;
using AxMapWinGIS;
using MapWinGIS;
namespace Examples
public partial class MapExamples
private const int CATEGORY_SELECTED = 0;
// <summary>
// Build a list of unique values of the given field and imlement zooming to them from the context menu
// </summary>
public void LabelSelection(AxMap axMap1, string dataPath)
axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
string filename = dataPath + "buildings.shp";
if (!File.Exists(filename))
System.Windows.Forms.MessageBox.Show("Couldn't file the file: " + filename);
Shapefile sf = new Shapefile();
sf.Open(filename, null);
m_layerHandle = axMap1.AddLayer(sf, true);
sf = axMap1.get_Shapefile(m_layerHandle); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
// let's add labels consisting of Name and type of building on a separate lines
sf.Labels.Generate("[Type]", tkLabelPositioning.lpCenter, false);
sf.Labels.FrameVisible = true;
sf.Labels.FrameType = tkLabelFrameType.lfRectangle;
// now let's add categories
Utils utils = new Utils(); // to specify colors
LabelCategory ct = sf.Labels.AddCategory("Selected");
ct = sf.Labels.AddCategory("Hidden");
ct.Visible = false;
axMap1.SendSelectBoxFinal = true;
axMap1.SendMouseDown = true;
axMap1.CursorMode = tkCursorMode.cmSelection;
MapEvents.SelectBoxFinal += AxMap1SelectBoxFinal2;
// <summary>
// Handles select box final event. Select the label that are within the rectangular specified by user
// </summary>
void AxMap1SelectBoxFinal2(object sender, _DMapEvents_SelectBoxFinalEvent e)
Shapefile sf = axMap1.get_Shapefile(m_layerHandle);
if (sf != null)
object labels = null;
object parts = null;
var ext = new Extents();
ext.SetBounds(e.left, e.bottom, 0.0, e.right,, 0.0);
if (sf.Labels.Select(ext, 0, SelectMode.INTERSECTION, ref labels, ref parts))
int[] labelIndices = labels as int[];
int[] partIndices = parts as int[];
for (int i = 0; i < labelIndices.Count(); i++)
Label label = sf.Labels.Label[labelIndices[i], partIndices[i]];
if (label.Category == -1) // selection will be appliedonly to the labels without category, so that hidden
label.Category = CATEGORY_SELECTED; //labels preserve their state
The selection mode, which determines which shapes will be considered as included in the rectangular s...
Definition: Enumerations.cs:149
The available positioning of the label relative to the parent shape.
Definition: Enumerations.cs:835
A list of named constants for some of the well-known colors.
Definition: Enumerations.cs:951
Available cursor modes. Determines the default respond of map to the action of user.
Definition: Enumerations.cs:344
The the available shapes of the frames for labels, i.e. rectangles drawn around the labels to ensure ...
Definition: Enumerations.cs:822
Commonly used map projections to be set in Form Designer (see AxMap.Projection property).
Definition: Enumerations.cs:1741
Map component for visualization of vector, raster or grid data.
Definition: AxMap.cs:56
void Redraw()
Redraws all layers in the map if the map is not locked.
Definition: AxMap.cs:183
Represents a rectangle on the map.
Definition: Extents.cs:49
Represents visualization options for labels displayed on the map.
Definition: LabelCategory.cs:115
bool Visible
Gets or sets a boolean value which indicates whether shapes that belongs to the category will be visi...
Definition: LabelCategory.cs:559
uint FrameBackColor
Gets or sets the back color of the frame.
Definition: LabelCategory.cs:278
Represents a single label on the map.
Definition: LabelClass.cs:65
int Category
The index of visualization category the label belongs to.
Definition: LabelClass.cs:73
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
Labels Labels
Gets or sets the instance of the Labels class associated with the shapefile.
Definition: Shapefile.cs:184
A utils object provides access to a set of utility functions to perform a variety of tasks on other o...
Definition: Utils.cs:20
uint ColorByName(tkMapColor Name)
Returns the numeric representation for the specified color.
Definition: Utils.cs:40
LabelCategory AddCategory(string Name)
Adds a visualization category for labels.
Definition: Labels.cs:290
int Generate(string Expression, tkLabelPositioning Method, bool LargestPartOnly)
Generates labels for each shape of the parent shapefile.
Definition: Labels.cs:490
bool Select(Extents BoundingBox, int Tolerance, SelectMode SelectMode, ref object LabelIndices, ref object PartIndices)
Returns the indices of all labels which are displayed in the given part of the map.
Definition: Labels.cs:649
bool FrameVisible
Gets or sets the values which indicates whether label's frame is visible.
Definition: Labels.cs:1357
tkLabelFrameType FrameType
Gets or sets the shape of the label's frame.
Definition: Labels.cs:1348
tkMapProjection Projection
Sets projection of the map. It providers 2 most commonly used coordinate system/projections to be eas...
Definition: AxMap.cs:2709
bool SendSelectBoxFinal
Gets or sets whether the map sends the SelectBoxFinal event.
Definition: AxMap.cs:598
tkCursorMode CursorMode
Gets or sets the cursor mode for the map.
Definition: AxMap.cs:456
bool SendMouseDown
Gets or sets whether the map sends mouse down events.
Definition: AxMap.cs:553
int AddLayer(object Object, bool visible)
Adds a layer to the map.
Definition: AxMap.cs:1342
Shapefile get_Shapefile(int layerHandle)
Gets shapefile object associated with the layer.
Definition: AxMap.cs:1546
bool Open(string shapefileName, ICallback cBack)
Opens shapefile from the disk.
Definition: Shapefile.cs:1430