Draw text on a MapControl


PurposeThis draw text sample application demonstrates the splined text rendering capabilities of ArcObjects. The user clicks the map to track a line, and the MapControl method DrawText is used to place the text within the TextBox along the tracked line. Note that at least two clicks are required for the line and text to appear on the MapControl.

The application uses the AddLayerFromFile method to load in the world continents sample data, which is then symbolized. The OnClick event either uses the TrackRectangle method to zoom in if the right or middle mouse button has been used or adds the new point to the line and updates the display through the refresh method. The refresh method is used to draw the esriViewForeground, thereby removing any previously drawn annotation and triggering the MapControl's OnAfterDraw event. The OnAfterDraw event uses the DrawShape and DrawText methods to draw the line and text onto the MapControl in response to the refresh of the esriViewForeground phase.

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo

How to use

See Using the samples for help on compiling, setting up the debugger, and running the sample (either an exe or dll).

  1. Enter text to annotate the map with.
  2. Use the left mouse button to trace a line on the map and use the right mouse button to zoom in.

AssemblyInfo.cs Assembly information
DrawText.cs Form file
Download the C# files
AssemblyInfo.vb Assembly information
DrawText.vb Form file
Download the VB.NET files

Download the files for all languages

See Also:

MapControl class
IMapControl2 interface