コード例 #1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IGraphicsContainer graphicsContainer = m_PageLayOutControl.GraphicsContainer;

            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_PageLayOutControl.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 = "图例";


            //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
            m_PageLayOutControl.AddElement(element, Type.Missing, Type.Missing, "图例", 0);

            //Refresh the PageLayoutControl
            m_PageLayOutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
コード例 #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            m_legend.Name  = this.textBoxElement.Text.Trim();
            m_legend.Title = this.textBox1.Text; //图例的标题
            ILayer      player;
            ILegendItem pLegendItem = null;

            #region //设置图例显示的项
            if (this.listBox2.Items.Count != 0)
            {
                m_legend.ClearItems();
                foreach (object item in this.listBox2.Items)   //设置需要的图例项  根据用户需要添加
                {
                    for (int j = 0; j < m_pageLayoutControl.ActiveView.FocusMap.LayerCount; j++)
                    {
                        player = m_pageLayoutControl.ActiveView.FocusMap.get_Layer(j);
                        if (player.Name == item.ToString())
                        {
                            IFeatureLayer pFLayer       = player as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFLayer.FeatureClass;
                            if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                            {
                                continue;
                            }
                            else
                            {
                                pLegendItem                  = new HorizontalLegendItemClass(); //图例项标签的样式
                                pLegendItem.Layer            = player;
                                pLegendItem.Columns          = 1;
                                pLegendItem.ShowDescriptions = false;
                                pLegendItem.ShowHeading      = false;
                                pLegendItem.ShowLabels       = true;
                                switch (comboBox1.SelectedItem.ToString().Trim())
                                {
                                case "所有文本符号":
                                    pLegendItem.LayerNameSymbol = pTextSymbol;   //设置字体样式
                                    pLegendItem.HeadingSymbol   = pTextSymbol;
                                    pLegendItem.LegendClassFormat.LabelSymbol = pTextSymbol;
                                    break;

                                case "所有图层名称":
                                    pLegendItem.LayerNameSymbol = pTextSymbol;
                                    break;

                                case "所有标题项":
                                    pLegendItem.HeadingSymbol = pTextSymbol;
                                    break;

                                case "所有标注项":
                                    pLegendItem.LegendClassFormat.LabelSymbol = pTextSymbol;
                                    break;

                                case "所有描述性文字":
                                    break;
                                }
                            }
                            m_legend.AddItem(pLegendItem);
                        }
                    }
                }
            }
            #endregion
            plegendFormat.DefaultPatchHeight = Convert.ToDouble(this.textBoxHeight.Text); //块的高度
            plegendFormat.DefaultPatchWidth  = Convert.ToDouble(this.textBoxWidth.Text);  //块的宽度


            #region //设置图例的底色边框
            IMapSurround pmapsurronud = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = pmapsurronud;
            m_FrameProperties            = (IFrameProperties)mapSurroundFrame;
            // m_SymbolBackground.FillSymbol.Color = ConvertColorToIColor(this.btnBackGroundColor.BackColor);
            m_FrameProperties.Background = (IBackground )m_SymbolBackground;
            // m_SymbolBorder.LineSymbol.Color = ConvertColorToIColor(this.btnBolderColor.BackColor);
            m_FrameProperties.Border = (IBorder)m_SymbolBorder;
            // m_SymbolShadow.FillSymbol.Color = ConvertColorToIColor(this.btnShadowColor.BackColor);
            m_FrameProperties.Shadow = (IShadow)m_SymbolShadow;

            #endregion



            IEnvelope pEnvelop = new EnvelopeClass();      //图例的位置
            pEnvelop.PutCoords(Convert.ToDouble(this.textBoxX.Text), Convert.ToDouble(this.textBoxY.Text),
                               Convert.ToDouble(this.textBoxX.Text) + Convert.ToDouble(this.textBoxWidth1.Text),
                               Convert.ToDouble(this.textBoxY.Text) + Convert.ToDouble(this.textBoxHeight1.Text));


            IElement m_element = mapSurroundFrame   as IElement;
            m_element.Geometry = pEnvelop;
            m_pageLayoutControl.AddElement(m_element, Type.Missing, Type.Missing, m_legend.Name, 0);
            m_pageLayoutControl.ActiveView.Refresh();
            this.Close();
        }