ArcObjects Library Reference  

MainForm

About the Editing using a custom form Sample

[C#]

MainForm.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;

namespace EditingUsingCustomForm
{
    public sealed partial class MainForm : Form
    {
        #region private members
        private IMapControl3 m_mapControl = null;
        #endregion

        #region class constructor
        public MainForm()
        {
            InitializeComponent();
        }
        #endregion

        private void MainForm_Load(object sender, EventArgs e)
        {        
            m_mapControl = (IMapControl3) axMapControl1.Object;

            //relative file path to the sample data from EXE location
            string filePath = @"..\..\..\data\USAMajorHighways";
 
            //Add Lakes layer
            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd);
            IFeatureLayer featureLayer = new FeatureLayerClass();
            featureLayer.Name = "Lakes";
            featureLayer.Visible = true;
            featureLayer.FeatureClass = workspace.OpenFeatureClass("us_lakes");

            #region create a SimplerRenderer
            IRgbColor color = new RgbColorClass();
            color.Red = 190;
            color.Green = 232;
            color.Blue = 255;

            ISimpleFillSymbol sym = new SimpleFillSymbolClass();
            sym.Color = color;

            ISimpleRenderer renderer = new SimpleRendererClass();
            renderer.Symbol = sym as ISymbol;
            #endregion

            ((IGeoFeatureLayer)featureLayer).Renderer = renderer as IFeatureRenderer;
            axMapControl1.Map.AddLayer((ILayer)featureLayer);

            //Add Highways layer
            featureLayer = new FeatureLayerClass();
            featureLayer.Name = "Highways";
            featureLayer.Visible = true;
            featureLayer.FeatureClass = workspace.OpenFeatureClass("usa_major_highways");
            axMapControl1.Map.AddLayer((ILayer)featureLayer);

            //******** Important *************
            //store a reference to this form (Mainform) using the EditHelper class
            EditHelper.TheMainForm = this;
            EditHelper.IsEditorFormOpen = false;

            //add the EditCmd command to the toolbar
            axEditorToolbar.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
            axEditorToolbar.AddItem(new EditCmd(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
             
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            //Warn users if the ArcGIS Engine samples used by this application have not been compiled
            ArrayList checkList = new ArrayList();
            checkList.Add("ReshapePolylineEditTask_CS.ReshapePolylineEditTask");
            checkList.Add("VertexCommands_CS.UsingOutOfBoxVertexCommands");

            Type t = null;
            bool success = true;

            foreach (string item in checkList)
            {
                t = Type.GetTypeFromProgID(item);

                if (t == null)
                {
                    success = false;
                    break;
                }
            }

            if (!success)
                MessageBox.Show("Editing will not function correctly until the C# ReshapePolylineEditTask and VertexCommands samples have been compiled. More information can be found in the 'How to use' section for this sample.",
                    "Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            
        }


        #region public properties

        // Returns the MapControl
        public IMapControl3 MapControl
        {
            get { return m_mapControl; }
        }

        #endregion

       
        




    }
}
[Visual Basic .NET]

MainForm.vb

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO
Imports System.Runtime.InteropServices

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.ADF
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.DataSourcesFile
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Display



Public Class MainForm
    <STAThread()> _
Shared Sub Main()
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine)
        Application.Run(New MainForm())
    End Sub

#Region "private members"
    Private m_mapControl As IMapControl3 = Nothing
#End Region

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        m_mapControl = CType(AxMapControl1.Object, IMapControl3)

        'relative file path to the sample data from EXE location
        Dim filePath As String = "..\..\..\data\USAMajorHighways"

        'Add Lakes layer
        Dim workspaceFactory As IWorkspaceFactory = New ShapefileWorkspaceFactoryClass()
        Dim workspace As IFeatureWorkspace = CType(workspaceFactory.OpenFromFile(filePath, AxMapControl1.hWnd), IFeatureWorkspace)
        Dim featureLayer As IFeatureLayer = New FeatureLayerClass()
        featureLayer.Name = "Lakes"
        featureLayer.Visible = True
        featureLayer.FeatureClass = workspace.OpenFeatureClass("us_lakes")

        'create a SimplerRenderer
        Dim color As IRgbColor = New RgbColorClass()
        color.Red = 190
        color.Green = 232
        color.Blue = 255

        Dim sym As ISimpleFillSymbol = New SimpleFillSymbolClass()
        sym.Color = color
        Dim renderer As ISimpleRenderer = New SimpleRendererClass()
        renderer.Symbol = sym
        CType(featureLayer, IGeoFeatureLayer).Renderer = renderer

        AxMapControl1.Map.AddLayer(CType(featureLayer, ILayer))

        'Add Highways layer
        featureLayer = New FeatureLayerClass()
        featureLayer.Name = "Highways"
        featureLayer.Visible = True
        featureLayer.FeatureClass = workspace.OpenFeatureClass("usa_major_highways")
        AxMapControl1.Map.AddLayer(CType(featureLayer, ILayer))

        '******** Important *************
        'store a reference to this form (Mainform) using the EditHelper class
        EditHelper.TheMainForm = Me
        EditHelper.IsEditorFormOpen = False

        'add the EditCmd command to the toolbar
        axEditorToolbar.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
        axEditorToolbar.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
        axEditorToolbar.AddItem("esriControls.ControlsAddDataCommand", 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)
        axEditorToolbar.AddItem(New EditCmd(), 0, -1, False, 0, esriCommandStyles.esriCommandStyleIconOnly)

    End Sub

    Private Sub MainForm_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown

        'Warn users if the ArcGIS Engine samples used by this application have not been compiled
        Dim checkList As ArrayList = New ArrayList()
        checkList.Add("ReshapePolylineEditTask_CS.ReshapePolylineEditTask")
        checkList.Add("VertexCommands_CS.CustomVertexCommands")

        Dim t As Type = Nothing
        Dim success As Boolean = True

        Dim item As String
        For Each item In checkList
            t = Type.GetTypeFromProgID(item)

            If t Is Nothing Then
                success = False
                Exit For
            End If
        Next

        If Not success Then
            MessageBox.Show("Editing will not function correctly until the C# ReshapePolylineEditTask and VertexCommands samples have been compiled. More information can be found in the 'How to use' section for this sample.", _
                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If

    End Sub

#Region "public properties"
    Public ReadOnly Property MapControl() As IMapControl3
        Get
            Return m_mapControl
        End Get
    End Property

#End Region

End Class