public override IElement GetElement(IPageLayout ipageLayout_0) { if (base.m_pElement == null) { this.CreateElement(ipageLayout_0); } if (base.m_pElement == null) { return(null); } IPoint position = this.GetPosition(ipageLayout_0); IEnvelope bounds = new EnvelopeClass(); base.m_pElement.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, bounds); if ((base.m_pElement as IMapSurroundFrame).MapSurround is ILegend) { ILegend mapSurround = (base.m_pElement as IMapSurroundFrame).MapSurround as ILegend; mapSurround.Map = (ipageLayout_0 as IActiveView).FocusMap; mapSurround.Refresh(); } if (!bounds.IsEmpty) { IEnvelope envelope2 = new EnvelopeClass(); envelope2.PutCoords(position.X, position.Y, position.X + bounds.Width, position.Y + bounds.Height); base.m_pElement.Geometry = envelope2; } return(base.m_pElement); }
private void button4_Click(object sender, System.EventArgs e) { //create the form with the SymbologyControl Form2 symbolForm = new Form2(); //Get the IStyleGalleryItem that has been selected in the SymbologyControl IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLinePatches); //release the form symbolForm.Dispose(); if (styleGalleryItem == null) { return; } //Find the legend IElement element = axPageLayoutControl1.FindElementByName("Legend", 1); if (element == null) { return; } //Get the IMapSurroundFrame IMapSurroundFrame mapSurroundFrame = (IMapSurroundFrame)element; if (mapSurroundFrame == null) { return; } //If a legend exists change the default area patch ILegend legend = (ILegend)mapSurroundFrame.MapSurround; legend.Format.DefaultLinePatch = (ILinePatch)styleGalleryItem.Item; //Update the legend legend.Refresh(); //Refresh the display axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void btnOK_Click(object sender, EventArgs e) { m_legend.Title = textBoxTitle.Text; m_legend.ClearItems(); int mapCount = m_legend_Complete.ItemCount; int legentCount = listBoxLegendItem.Items.Count; for (int i = 0; i < legentCount; i++) { for (int j = 0; j < mapCount; j++) { if (listBoxLegendItem.Items[i].ToString() == listBoxMapItem.Items[j].ToString()) { m_legend.AddItem(m_legend_Complete.get_Item(j)); } } } if (checkBoxIsTitleShow.Checked == false) { m_legend.Title = ""; } m_legend.Refresh(); }
//更新图例 private void UpdateLegend() { //边框、背景、阴影的间距 if (txtBorderGap.Text != null && pSymbolBorder != null) { pSymbolBorder.Gap = double.Parse(this.txtBorderGap.Text); } if (txtBackgroundGap.Text != null && pSymbolBackground != null) { pSymbolBackground.Gap = double.Parse(this.txtBackgroundGap.Text); } if (txtShadowX.Text != null && pSymbolShadow != null) { pSymbolShadow.VerticalSpacing = double.Parse(this.txtShadowX.Text); } if (txtShadowY.Text != null && pSymbolShadow != null) { pSymbolShadow.HorizontalSpacing = double.Parse(this.txtShadowY.Text); } //边框、背景、阴影的角度 if (txtBorderAngle.Text != null && pSymbolBorder != null) { pSymbolBorder.CornerRounding = short.Parse(txtBorderAngle.Text); } if (txtBackgroundAngle.Text != null && pSymbolBackground != null) { pSymbolBackground.CornerRounding = short.Parse(txtBackgroundAngle.Text); } if (txtShadowAngle.Text != null && pSymbolShadow != null) { pSymbolShadow.CornerRounding = short.Parse(txtShadowAngle.Text); } //边框、背景、阴影 IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties; if (pSymbolBorder != null) { pFrameProperties.Border = pSymbolBorder; } if (pSymbolBackground != null) { pFrameProperties.Background = pSymbolBackground; } if (pSymbolShadow != null) { pFrameProperties.Shadow = pSymbolShadow; } ILegendFormat pLegendFormat = new LegendFormatClass(); //标题设置 显示 if (this.cBoxShowTitle.Checked == true) { pLegendFormat.ShowTitle = true; } else { pLegendFormat.ShowTitle = false; } //标题样式 if (pTitleSymbol != null) { pLegendFormat.TitleSymbol = pTitleSymbol; } //图面样式以及高度和样式设计 if (pLinePatch != null) { pLegendFormat.DefaultLinePatch = pLinePatch; } if (pAreaPatch != null) { pLegendFormat.DefaultAreaPatch = pAreaPatch; } if (txtPatchWith.Text != null) { pLegendFormat.DefaultPatchWidth = double.Parse(txtPatchWith.Text); } if (txtPatchHeight.Text != null) { pLegendFormat.DefaultPatchHeight = double.Parse(txtPatchHeight.Text); } //第四界面从上到下图例各部分之间的距离 pLegendFormat.TitleGap = double.Parse(txtTitleAndLegend.Text); pLegendFormat.VerticalItemGap = double.Parse(txtLegendItems.Text); pLegendFormat.HorizontalItemGap = double.Parse(txtColumns.Text); pLegendFormat.HeadingGap = double.Parse(txtHeadings.Text); pLegendFormat.TextGap = double.Parse(txtLabelsAndDescription.Text); pLegendFormat.VerticalPatchGap = double.Parse(txtPatchesV.Text); pLegendFormat.HorizontalPatchGap = double.Parse(txtPatchAndLabels.Text); //样式添加到图例 Legend.Title = this.txtLegendTitle.Text; Legend.Format = pLegendFormat; //地图链接 Legend.AutoVisibility = cBoxAddVisibleLayer.Checked; //只显示显示的图层 Legend.AutoAdd = cBoxAddNewLayer.Checked; //自动添加显示的图层 Legend.AutoReorder = cBoxNewOrder.Checked; //按照图层顺序排列图例 //Legend.ClearItems(); //Legend.Refresh(); //图例列数 double pLegendColumn = double.Parse(this.LegendColumn.Text); //图例中要包含的图层个数为 pSelectedidx.Count double pLegendItemCount = pSelectedidx.Count; //计算图例分裂的位置 int ColumnPos = (int)(pLegendItemCount / pLegendColumn); double remainder = (pLegendItemCount % pLegendColumn) / pLegendColumn; if (remainder >= 0.5) { ColumnPos = ColumnPos + 1; } for (int i = 0; i < pSelectedidx.Count; i++) { ILegendItem pLegendItem = new HorizontalLegendItemClass(); pLegendItem.Layer = pMap.get_Layer(pSelectedidx[i]); int lengendinex = 0;//记录同名图层在legend中的位置 for (int j = 0; j < Legend.ItemCount; j++) { if (Legend.Item[j].Layer == pLegendItem.Layer) { lengendinex = j; break; } } pLegendItem.ShowDescriptions = Legend.Item[lengendinex].ShowDescriptions; pLegendItem.ShowHeading = Legend.Item[lengendinex].ShowHeading; pLegendItem.ShowLabels = Legend.Item[lengendinex].ShowLabels; pLegendItem.ShowLayerName = Legend.Item[lengendinex].ShowLayerName; pLegendItem.HeadingSymbol = Legend.Item[lengendinex].HeadingSymbol; pLegendItem.LayerNameSymbol = Legend.Item[lengendinex].LayerNameSymbol; pLegendItem.LegendClassFormat = Legend.Item[lengendinex].LegendClassFormat; //列数设置 //列数设置 if (ColumnPos <= 1) { pLegendItem.NewColumn = true; } else if (ColumnPos > 1 && i > 0) { int columnI = i % ColumnPos; if (columnI == 0) { pLegendItem.NewColumn = true; } } legendlist.Add(pLegendItem); } Legend.ClearItems(); Legend.Refresh(); for (int i = 0; i < legendlist.Count; i++) { Legend.AddItem(legendlist[i]); } ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout; pLegendLayout.ScaleGraphicsOnResize = false; m_hookHelper.ActiveView.Refresh(); }