HOW TO

Dynamically add Map Control to a C# .NET application

Last Published: April 25, 2020

Summary

** Internal Publish Only! This article may contain information that is not intended for external circulation. **

A license key is required when distributing a dynamically created Map Control. This article shows how to programmatically add a Map Control to C# .NET application using a license key.

Procedure

The license key for MapObjects is "Copyright (c) 1999 ESRI, Inc.". The license key is located in MO20.lic file.
  1. Open a new C# .NET application and click Project > Add Reference then click the .NET tab and select the following assemblies:


    Code:
    MapObjects2 Core Interop Assembly
    MapObjects2 AxMap Host Interop Assembly


    If the application requires MemTable and Custom extension libraries,select the following assemblies:

    Code:
    MapObjects2 Custom Interop Assembly
    MapObjects2 MemTable Interop Assembly

  2. Add a Button control to the form and in the button's click event paste the following code:

    Code:
    private void button1_Click(object sender, System.EventArgs e)

    {
    //create a new instance of Map Control
    ESRI.MapObjects2.Core.AxMap mMap = new ESRI.MapObjects2.Core.AxMap();

    //Add MapObjects license key to the control
    System.Reflection.FieldInfo f =typeof(AxHost).GetField("licenseKey", System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.Instance);
    f.SetValue(mMap, "Copyright (c) 1999 ESRI, Inc.");

    //Add Map Control to the Form
    Controls.Add(mMap);
    mMap.Show();

    }

Article ID:000006256

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options