AE+C# 向AxPageLayoutControl添加自定义标注


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;
            }
          
        }

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值