This example demonstrates how to Adds labels to the layer without using automated procedures like Labels.Generate. Here is a screenshot with the results of the code.
using System; using System.Windows.Forms; using AxMapWinGIS; using MapWinGIS; using System.IO; public partial class MapExamples { // <summary> // Adds labels to the layer without using automated procedures like Labels.Generate. // </summary> public void GenerateLabelsManually(AxMap axMap1, string dataPath) { string filename = dataPath + "buildings.shp"; if (!File.Exists(filename)) { MessageBox.Show("Failed to open file: " + filename); return; } Shapefile sf = new Shapefile(); if (!sf.Open(filename, null)) { MessageBox.Show("Failed to open shapefile: " + sf.get_ErrorMsg(sf.LastErrorCode)); } else { int fieldIndex = 0; for (int i = 0; i < sf.NumShapes; i++) { Shape shp = sf.get_Shape(i); string text = sf.get_CellValue(fieldIndex, i).ToString(); Point pnt = shp.Centroid; sf.Labels.AddLabel(text, pnt.x, pnt.y, 0.0, -1); // the old method should be used like this //axMap1.AddLabel(layerHandle, text, 0, pnt.x, pnt.y, tkHJustification.hjCenter); } sf.Labels.Synchronized = true; axMap1.AddLayer(sf, true); } } }
1.7.6.1