private void button1_Click(object sender, System.EventArgs e)
        {
            //Get the GraphicsContainer
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer;

            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }

            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.Legend";

            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }
            //Set the name
            mapSurroundFrame.MapSurround.Name = "Legend";

            //Envelope for the legend
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(1, 1, 3.4, 2.4);

            //Set the geometry of the MapSurroundFrame
            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelope;

            //Add the legend to the PageLayout
            axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "Legend", 0);

            //Refresh the PageLayoutControl
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            //disable/enable buttons
            cmdDraw.Enabled       = false;
            cmdDelete.Enabled     = true;
            cmdChangeArea.Enabled = true;
            cmdChangeLine.Enabled = true;
        }
Exemplo n.º 2
0
        private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e)
        {
            if (e.button != 2)
            {
                return;
            }

            //Create a new point
            IPoint pPoint = new PointClass();

            pPoint.PutCoords(e.pageX, e.pageY);

            //Create a new text element
            ITextElement textElement = new TextElementClass();

            //Set the text to display today's date
            textElement.Text = DateTime.Now.ToShortDateString();

            //Add element to graphics container using the CommandsEnvironment default text symbol
            axPageLayoutControl1.AddElement((IElement)textElement, pPoint, m_graphicProperties.TextSymbol, "", 0);
            //Refresh the graphics
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }