About the Draw text on a MapControl Sample
[C#]
DrawText.cs
using System; using System.Windows.Forms; using System.Drawing; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.ADF.COMSupport; using ESRI.ArcGIS; namespace DrawText { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { public System.Windows.Forms.TextBox Text1; public System.Windows.Forms.Label Label1; public System.Windows.Forms.Button cmdReset; public System.Windows.Forms.Button cmdFullExtent; public System.Windows.Forms.Label Label3; public System.Windows.Forms.Label Label2; private IPointCollection m_PointCollection; private IPolyline m_Polyline; private ESRI.ArcGIS.Controls.AxMapControl axMapControl1; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { //Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown(); if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.Text1 = new System.Windows.Forms.TextBox(); this.Label1 = new System.Windows.Forms.Label(); this.cmdReset = new System.Windows.Forms.Button(); this.cmdFullExtent = new System.Windows.Forms.Button(); this.Label3 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); this.axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.SuspendLayout(); // // Text1 // this.Text1.AcceptsReturn = true; this.Text1.BackColor = System.Drawing.SystemColors.Window; this.Text1.Cursor = System.Windows.Forms.Cursors.IBeam; this.Text1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Text1.ForeColor = System.Drawing.SystemColors.WindowText; this.Text1.Location = new System.Drawing.Point(8, 280); this.Text1.MaxLength = 0; this.Text1.Name = "Text1"; this.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Text1.Size = new System.Drawing.Size(321, 25); this.Text1.TabIndex = 4; this.Text1.Text = "Put a map in your app..."; // // Label1 // this.Label1.BackColor = System.Drawing.SystemColors.Control; this.Label1.Cursor = System.Windows.Forms.Cursors.Default; this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label1.ForeColor = System.Drawing.SystemColors.ControlText; this.Label1.Location = new System.Drawing.Point(8, 264); this.Label1.Name = "Label1"; this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label1.Size = new System.Drawing.Size(129, 17); this.Label1.TabIndex = 5; this.Label1.Text = "Enter text:"; // // cmdReset // this.cmdReset.BackColor = System.Drawing.SystemColors.Control; this.cmdReset.Cursor = System.Windows.Forms.Cursors.Default; this.cmdReset.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdReset.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdReset.Location = new System.Drawing.Point(344, 208); this.cmdReset.Name = "cmdReset"; this.cmdReset.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdReset.Size = new System.Drawing.Size(73, 25); this.cmdReset.TabIndex = 7; this.cmdReset.Text = "Clear Text"; this.cmdReset.UseVisualStyleBackColor = false; this.cmdReset.Click += new System.EventHandler(this.cmdReset_Click); // // cmdFullExtent // this.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control; this.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFullExtent.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFullExtent.Location = new System.Drawing.Point(344, 240); this.cmdFullExtent.Name = "cmdFullExtent"; this.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFullExtent.Size = new System.Drawing.Size(73, 25); this.cmdFullExtent.TabIndex = 6; this.cmdFullExtent.Text = "Full Extent"; this.cmdFullExtent.UseVisualStyleBackColor = false; this.cmdFullExtent.Click += new System.EventHandler(this.cmdFullExtent_Click); // // Label3 // this.Label3.BackColor = System.Drawing.SystemColors.Control; this.Label3.Cursor = System.Windows.Forms.Cursors.Default; this.Label3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label3.ForeColor = System.Drawing.SystemColors.ControlText; this.Label3.Location = new System.Drawing.Point(344, 72); this.Label3.Name = "Label3"; this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label3.Size = new System.Drawing.Size(81, 65); this.Label3.TabIndex = 8; this.Label3.Text = "Right mouse button to drag a rectangle to zoom in."; // // Label2 // this.Label2.BackColor = System.Drawing.SystemColors.Control; this.Label2.Cursor = System.Windows.Forms.Cursors.Default; this.Label2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label2.ForeColor = System.Drawing.SystemColors.ControlText; this.Label2.Location = new System.Drawing.Point(344, 8); this.Label2.Name = "Label2"; this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label2.Size = new System.Drawing.Size(81, 65); this.Label2.TabIndex = 9; this.Label2.Text = "Left mouse button to trace a line to draw text along. "; // // axMapControl1 // this.axMapControl1.Location = new System.Drawing.Point(8, 8); this.axMapControl1.Name = "axMapControl1"; this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState"))); this.axMapControl1.Size = new System.Drawing.Size(320, 248); this.axMapControl1.TabIndex = 10; this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown); this.axMapControl1.OnAfterDraw += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnAfterDrawEventHandler(this.axMapControl1_OnAfterDraw); // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(347, 140); this.axLicenseControl1.Name = "axLicenseControl1"; this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState"))); this.axLicenseControl1.Size = new System.Drawing.Size(32, 32); this.axLicenseControl1.TabIndex = 11; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(432, 310); this.Controls.Add(this.axLicenseControl1); this.Controls.Add(this.axMapControl1); this.Controls.Add(this.cmdReset); this.Controls.Add(this.cmdFullExtent); this.Controls.Add(this.Label3); this.Controls.Add(this.Label2); this.Controls.Add(this.Text1); this.Controls.Add(this.Label1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { if (!RuntimeManager.Bind(ProductCode.Engine)) { if (!RuntimeManager.Bind(ProductCode.Desktop)) { MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down."); return; } } Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { //Find sample data by navigating two folders up string sFilePath = @"..\..\..\Data\World\Continents.lyr"; //Add sample 'country' shapefile data axMapControl1.AddLayerFromFile(sFilePath); //Set the extent axMapControl1.Extent = axMapControl1.get_Layer(0).AreaOfInterest; //Grab hold of the IgeoFeaturelayer interface on the layer //in the map control in order to symbolize the data IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer) axMapControl1.get_Layer(0); //Create a simple renderer and grab hold of ISimpleRenderer interface ISimpleRenderer simpleRenderer = new SimpleRendererClass(); //Create a fill symbol and grab hold of the ISimpleFillSymbol interface ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); //Create a line symbol and grab hold of the ISimpleLineSymbol interface ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); //Assign line symbol and fill symbol properties lineSymbol.Width = 0.1; lineSymbol.Color = GetRGBColor(255, 0, 0); //Red fillSymbol.Outline = lineSymbol; fillSymbol.Color = GetRGBColor(0, 0, 255); //Blue //Set the symbol property of the renderer simpleRenderer.Symbol = (ISymbol) fillSymbol; //Set the renderer property of the geo feature layer geoFeatureLayer.Renderer = (IFeatureRenderer) simpleRenderer; } private void cmdFullExtent_Click(object sender, System.EventArgs e) { //Assign map controls extent property to the full extent of all the layers axMapControl1.Extent = axMapControl1.FullExtent; } private void cmdReset_Click(object sender, System.EventArgs e) { //Get rid of the line and points collection m_Polyline = null; m_PointCollection = null; //Refresh the foreground thereby removing any text annotation axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing); } private IRgbColor GetRGBColor(int red,int green, int blue) { //Create rgb color and grab hold of the IRGBColor interface IRgbColor rGB = new RgbColorClass(); //Set rgb color properties rGB.Red = red; rGB.Green = green; rGB.Blue = blue; rGB.UseWindowsDithering = true; return rGB; } private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { //If left hand mouse button if (e.button == 1) { //Create a point and grab hold of the IPoint interface IPoint point = new PointClass(); //Set point properties point.X = e.mapX; point.Y = e.mapY; //If this is the first point of a new line if (m_Polyline == null) { //Create the forms private polyline member and grab hold of the IPolyline interface m_Polyline = new PolylineClass(); } //QI for the IPointsCollection interface using the IPolyline interface object o = Type.Missing; //object o1 = m_PointCollection.PointCount-1; m_PointCollection = (IPointCollection) m_Polyline; m_PointCollection.AddPoint(point, ref o, ref o); //Refresh the foreground thereby removing any text annotation axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing,Type.Missing); } else { //If right or middle mouse button zoom to user defined rectangle //Create an envelope and grab hold of the IEnvelope interface IEnvelope envelope = axMapControl1.TrackRectangle(); //If user dragged a rectangle if (envelope != null) { //Set map controls extent property axMapControl1.Extent = envelope; } } } private void axMapControl1_OnAfterDraw(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent e) { //If foreground refreshed if (e.viewDrawPhase == (int) esriViewDrawPhase.esriViewForeground) { //If a line object for splining text exists if (m_Polyline != null) { //Ensure there's at least two points in the line if (m_PointCollection.PointCount > 1) { //Create a line symbol and grab hold of the ILineSymbol interface ILineSymbol lineSymbol = new SimpleLineSymbolClass(); //Set line symbol properties lineSymbol.Color = GetRGBColor(0, 0, 0); lineSymbol.Width = 2; //Create a text symbol and grab hold of the ITextSymbol interface ITextSymbol textSymbol = new TextSymbolClass(); //Create a system drawing font symbol with the specified properties System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16, FontStyle.Bold); //Set the text symbol font by getting the IFontDisp interface textSymbol.Font = (stdole.IFontDisp) OLE.GetIFontDispFromFont(drawFont); textSymbol.Color = GetRGBColor(0, 0, 0); //Create a text path and grab hold of the ITextPath interface ITextPath textPath = new BezierTextPathClass(); //to spline the text //Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol) textSymbol; //Set the text path of the simple text symbol simpleTextSymbol.TextPath = textPath; //Draw the line object and spline the user text around the line object oLineSymbol = lineSymbol; object oTextSymbol = textSymbol; axMapControl1.DrawShape(m_Polyline, ref oLineSymbol); axMapControl1.DrawText(m_Polyline, Text1.Text, ref oTextSymbol); } } } } } }
[Visual Basic .NET]
DrawText.vb
Imports ESRI.ArcGIS.Controls Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Display Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.ADf.COMSupport.OLE Imports ESRI.ArcGIS Public Class Form1 Inherits System.Windows.Forms.Form <STAThread()> _ Shared Sub Main() 'Load runtime If Not RuntimeManager.Bind(ProductCode.Engine) Then If Not RuntimeManager.Bind(ProductCode.Desktop) Then MessageBox.Show("Unable to bind to ArcGIS Engine runtime. Application shutting down.") System.Environment.Exit(1) ' Force exit or other indication in the application End If End If Application.Run(New Form1()) End Sub #Region "Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean) 'Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown() If Disposing Then If Not components Is Nothing Then components.Dispose() End If End If MyBase.Dispose(Disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer Public ToolTip1 As System.Windows.Forms.ToolTip Public WithEvents Text1 As System.Windows.Forms.TextBox Public WithEvents cmdReset As System.Windows.Forms.Button Public WithEvents cmdFullExtent As System.Windows.Forms.Button Public WithEvents Label3 As System.Windows.Forms.Label Public WithEvents Label2 As System.Windows.Forms.Label Public WithEvents Label1 As System.Windows.Forms.Label 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents AxMapControl1 As ESRI.ArcGIS.Controls.AxMapControl Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) Me.Text1 = New System.Windows.Forms.TextBox Me.cmdReset = New System.Windows.Forms.Button Me.cmdFullExtent = New System.Windows.Forms.Button Me.Label3 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label1 = New System.Windows.Forms.Label Me.AxMapControl1 = New ESRI.ArcGIS.Controls.AxMapControl Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl CType(Me.AxMapControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Text1 ' Me.Text1.AcceptsReturn = True Me.Text1.AutoSize = False Me.Text1.BackColor = System.Drawing.SystemColors.Window Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam Me.Text1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Text1.ForeColor = System.Drawing.SystemColors.WindowText Me.Text1.Location = New System.Drawing.Point(8, 304) Me.Text1.MaxLength = 0 Me.Text1.Name = "Text1" Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text1.Size = New System.Drawing.Size(321, 25) Me.Text1.TabIndex = 2 Me.Text1.Text = "Put a map in your app..." ' 'cmdReset ' Me.cmdReset.BackColor = System.Drawing.SystemColors.Control Me.cmdReset.Cursor = System.Windows.Forms.Cursors.Default Me.cmdReset.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdReset.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdReset.Location = New System.Drawing.Point(336, 216) Me.cmdReset.Name = "cmdReset" Me.cmdReset.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdReset.Size = New System.Drawing.Size(73, 25) Me.cmdReset.TabIndex = 1 Me.cmdReset.Text = "Clear Text" ' 'cmdFullExtent ' Me.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control Me.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFullExtent.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFullExtent.Location = New System.Drawing.Point(336, 248) Me.cmdFullExtent.Name = "cmdFullExtent" Me.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFullExtent.Size = New System.Drawing.Size(73, 25) Me.cmdFullExtent.TabIndex = 0 Me.cmdFullExtent.Text = "Full Extent" ' 'Label3 ' Me.Label3.BackColor = System.Drawing.SystemColors.Control Me.Label3.Cursor = System.Windows.Forms.Cursors.Default Me.Label3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText Me.Label3.Location = New System.Drawing.Point(336, 80) Me.Label3.Name = "Label3" Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label3.Size = New System.Drawing.Size(81, 65) Me.Label3.TabIndex = 4 Me.Label3.Text = "Right mouse button to drag a rectangle to zoom in." ' 'Label2 ' Me.Label2.BackColor = System.Drawing.SystemColors.Control Me.Label2.Cursor = System.Windows.Forms.Cursors.Default Me.Label2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText Me.Label2.Location = New System.Drawing.Point(336, 16) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label2.Size = New System.Drawing.Size(81, 65) Me.Label2.TabIndex = 5 Me.Label2.Text = "Left mouse button to trace a line to draw text along. " ' 'Label1 ' Me.Label1.BackColor = System.Drawing.SystemColors.Control Me.Label1.Cursor = System.Windows.Forms.Cursors.Default Me.Label1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText Me.Label1.Location = New System.Drawing.Point(8, 288) Me.Label1.Name = "Label1" Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label1.Size = New System.Drawing.Size(129, 17) Me.Label1.TabIndex = 3 Me.Label1.Text = "Enter text:" ' 'AxMapControl1 ' Me.AxMapControl1.Location = New System.Drawing.Point(8, 8) Me.AxMapControl1.Name = "AxMapControl1" Me.AxMapControl1.OcxState = CType(resources.GetObject("AxMapControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxMapControl1.Size = New System.Drawing.Size(320, 272) Me.AxMapControl1.TabIndex = 6 ' 'AxLicenseControl1 ' Me.AxLicenseControl1.Enabled = True Me.AxLicenseControl1.Location = New System.Drawing.Point(120, 24) Me.AxLicenseControl1.Name = "AxLicenseControl1" Me.AxLicenseControl1.OcxState = CType(resources.GetObject("AxLicenseControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxLicenseControl1.Size = New System.Drawing.Size(200, 50) Me.AxLicenseControl1.TabIndex = 7 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.BackColor = System.Drawing.SystemColors.Control Me.ClientSize = New System.Drawing.Size(420, 350) Me.Controls.Add(Me.AxLicenseControl1) Me.Controls.Add(Me.AxMapControl1) Me.Controls.Add(Me.Text1) Me.Controls.Add(Me.cmdReset) Me.Controls.Add(Me.cmdFullExtent) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Cursor = System.Windows.Forms.Cursors.Default Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Location = New System.Drawing.Point(4, 23) Me.Name = "Form1" Me.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text = "Draw Text Example" CType(Me.AxMapControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private m_pPointCollection As IPointCollection Private m_pPolyline As IPolyline Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load Dim sFilePath As String 'Find sample data by navigating two folders up sFilePath = "..\..\..\Data\World\Continents.lyr" 'Add sample 'country' shapefile data AxMapControl1.AddLayerFromFile(sFilePath) 'Set the extent AxMapControl1.Extent = AxMapControl1.get_Layer(0).AreaOfInterest Dim pGeoFeatureLayer As IGeoFeatureLayer 'Grab hold of the IgeoFeaturelayer interface on the layer 'in the map control in order to symbolize the data pGeoFeatureLayer = AxMapControl1.get_Layer(0) Dim pSimpleRenderer As ISimpleRenderer Dim pFillSymbol As ISimpleFillSymbol Dim pLineSymbol As ISimpleLineSymbol 'Create a simple renderer and grab hold of ISimpleRenderer interface pSimpleRenderer = New SimpleRendererClass 'Create a fill symbol and grab hold of the ISimpleFillSymbol interface pFillSymbol = New SimpleFillSymbolClass 'Create a line symbol and grab hold of the ISimpleLineSymbol interface pLineSymbol = New SimpleLineSymbolClass 'Assign line symbol and fill symbol properties pLineSymbol.Width = 0.1 pLineSymbol.Color = GetRGBColor(255, 0, 0) 'Red pFillSymbol.Outline = pLineSymbol pFillSymbol.Color = GetRGBColor(0, 0, 255) 'Blue 'Set the symbol property of the renderer pSimpleRenderer.Symbol = pFillSymbol 'Set the renderer property of the geo feature layer pGeoFeatureLayer.Renderer = pSimpleRenderer End Sub Private Sub cmdFullExtent_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFullExtent.Click 'Assign map controls extent property to the full extent of all the layers AxMapControl1.Extent = AxMapControl1.FullExtent End Sub Private Sub cmdReset_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReset.Click 'Get rid of the line and points collection m_pPolyline = Nothing m_pPointCollection = Nothing 'Refresh the foreground thereby removing any text annotation AxMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Nothing, Nothing) End Sub Private Function GetRGBColor(ByRef pRed As Integer, ByRef pGreen As Integer, ByRef pBlue As Integer) As ESRI.ArcGIS.Display.IRgbColor Dim pRGB As IRgbColor 'Create rgb color and grab hold of the IRGBColor interface pRGB = New RgbColor 'Set rgb color properties With pRGB .Red = pRed .Green = pGreen .Blue = pBlue .UseWindowsDithering = True End With GetRGBColor = pRGB End Function Private Sub AxMapControl1_OnAfterDraw(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnAfterDrawEvent) Handles AxMapControl1.OnAfterDraw 'If foreground refreshed Dim pLineSymbol As ILineSymbol Dim pTextSymbol As ITextSymbol Dim pTextPath As ITextPath Dim pSimpleTextSymbol As ISimpleTextSymbol If e.viewDrawPhase = esriViewDrawPhase.esriViewForeground Then 'If a line object for splining text exists If Not m_pPolyline Is Nothing Then 'Ensure there's at least two points in the line If m_pPointCollection.PointCount > 1 Then 'Create a line symbol and grab hold of the ILineSymbol interface pLineSymbol = New SimpleLineSymbolClass 'Set line symbol properties pLineSymbol.Color = GetRGBColor(0, 0, 0) pLineSymbol.Width = 2 'Create text symbol 'Create a text symbol and grab hold of the ITextSymbol interface pTextSymbol = New TextSymbolClass ''Create a system drawing font symbol with the specified properties Dim drawFont As New System.Drawing.Font("Arial", 16, FontStyle.Bold) 'Set the text symbol font by getting the IFontDisp interface pTextSymbol.Font = GetIFontDispFromFont(drawFont) pTextSymbol.Color = GetRGBColor(0, 0, 0) 'Create a text path and grab hold of the ITextPath interface pTextPath = New BezierTextPathClass 'to spline the text 'Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface pSimpleTextSymbol = pTextSymbol 'Set the text path of the simple text symbol pSimpleTextSymbol.TextPath = pTextPath 'Draw the line object and spline the user text around the line AxMapControl1.DrawShape(m_pPolyline, CType(pLineSymbol, Object)) AxMapControl1.DrawText(m_pPolyline, Text1.Text, CType(pTextSymbol, Object)) End If End If End If End Sub Private Sub AxMapControl1_OnMouseDown(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles AxMapControl1.OnMouseDown 'If left hand mouse button Dim pPoint As IPoint Dim pEnvelope As IEnvelope If e.button = 1 Then 'Create a point and grab hold of the IPoint interface pPoint = New PointClass 'Set point properties pPoint.X = e.mapX pPoint.Y = e.mapY 'If this is the first point of a new line If m_pPolyline Is Nothing Then 'Create the forms private polyline member and grab hold of the IPolyline interface m_pPolyline = New PolylineClass End If 'QI for the IPointsCollection interface using the IPolyline interface m_pPointCollection = m_pPolyline m_pPointCollection.AddPoint(pPoint) 'Refresh the foreground thereby removing any text annotation AxMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Nothing, Nothing) Else 'If right or middle mouse button zoom to user defined rectangle 'Create an envelope and grab hold of the IEnvelope interface pEnvelope = AxMapControl1.TrackRectangle 'If user dragged a rectangle If Not pEnvelope Is Nothing Then 'Set map controls extent property AxMapControl1.Extent = pEnvelope End If End If End Sub End Class