![AE+C# 向AxPageLayoutControl添加自定义标注_第1张图片](http://img.e-com-net.com/image/info8/1103568b283d4cda815b1ba5406b1ff4.jpg)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
namespace LeakOil.Layout.Text
{
public partial class TextSymbols : Form
{
private AxPageLayoutControl pAxPageLayoutControl;
//private AxSymbologyControl axSymbologyControl1;
private IStyleGalleryItem m_StyleGalleryItem;
//private ITextSymbol m_textSymbol;
public TextSymbols(AxPageLayoutControl axPageLayoutControl)
{
InitializeComponent();
pAxPageLayoutControl = axPageLayoutControl;
}
private void TextSymbols_Load(object sender, EventArgs e)
{
//Add values for the text size to the combo box
for (int i = 1; i <= 50; i++)
{
comboBox1.Items.Add(i.ToString()+"pt");
}
comboBox1.SelectedIndex = 0;
//Get the ArcGIS install location
string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;
//Load the ESRI.ServerStyle file into the SymbologyControl
axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle");
}
public static string text;
public static double size;
private void buttonOK_Click(object sender, EventArgs e)
{
text=textBox1.Text.ToString();
size = (double)comboBox1.SelectedIndex + 1.0;
MessageBox.Show(size.ToString());
this.Hide();
}
private void buttonNO_Click(object sender, EventArgs e)
{
m_StyleGalleryItem = null;
//Hide the form
this.Hide();
}
public IStyleGalleryItem GetItem(ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass)
{
m_StyleGalleryItem = null;
//Disable ok button
buttonOK.Enabled = false;
//Set the style class
axSymbologyControl1.StyleClass = styleClass;
//Unselect any selected item in the current style class
axSymbologyControl1.GetStyleClass(styleClass).UnselectItem();
//Show the modal form
this.ShowDialog();
//Return the selected label style
return m_StyleGalleryItem;
}
private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e)
{
//Get the selected item
m_StyleGalleryItem = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass).GetSelectedItem();
//Enable ok button
buttonOK.Enabled = true;
}
public void TextSymbolsPageLayoutOnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e,double size,string text)
{
//Check if the right button of the mouse was clicked
if (e.button != 2) return;
//Ensure a text symbol has been selected
if (MainForm.m_textSymbol == null) return;
//Create a point and set its coordinates
IPoint point = new PointClass();
point.X = e.pageX;
point.Y = e.pageY;
//Create a text element
ITextElement textElement = new TextElementClass();
textElement.Text = text;
//Set the size of the text
//i = (double)comboBox1.SelectedIndex+1.0;
MainForm.m_textSymbol.Size = size;
//Set the TextElement symbol to that of the selected text symbol
textElement.Symbol = MainForm.m_textSymbol;
textElement.ScaleText = true;
//QI to IElment
IElement element = (IElement)textElement;
//Set the TextElement's geometry
element.Geometry = point;
//Add the element to the GraphicsContainer
pAxPageLayoutControl.AddElement(element, Type.Missing, Type.Missing, "Text", 0);
//pAxPageLayoutControl.ActiveView.GraphicsContainer.AddElement(element, 0);
//Refresh the PageLayout
pAxPageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null);
}
}
}
主界面调用
//添加text要素
public static ITextSymbol m_textSymbol;
private void barButtonText_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
pageFlag=4;
LeakOil.Layout.Text.TextSymbols textsymbols = new Layout.Text.TextSymbols(axPageLayoutControl1);
IStyleGalleryItem styleGalleryItem = textsymbols.GetItem(esriSymbologyStyleClass.esriStyleClassTextSymbols);
if (styleGalleryItem == null) return;
m_textSymbol = (ITextSymbol)styleGalleryItem.Item;
textsymbols.Dispose();
}
private void axPageLayoutControl1_OnMouseDown(object sender, IPageLayoutControlEvents_OnMouseDownEvent e)
{
switch (pageFlag)
{
case 4:
LeakOil.Layout.Text.TextSymbols textsymbols = new Layout.Text.TextSymbols(axPageLayoutControl1);
textsymbols.TextSymbolsPageLayoutOnMouseDown(sender, e, LeakOil.Layout.Text.TextSymbols.size, LeakOil.Layout.Text.TextSymbols.text);
break;
}
}