来自:https://www.cnblogs.com/caodajieup/archive/2011/09/28/2193891.html
ArcEngine实现pagelayout中文本元素的属性对话框
效果如上图,有点难看
源码如下
public partial class Properties : Form
{
IPageLayoutControlDefault pPageLayout = null;
ITextElement pTextElement = null;
ITextSymbol pTextSymbol = null;
ICharacterOrientation pCharacterOrientation = null;
IGraphicsContainer pGraphicsContainer = null;
public Properties(IPageLayoutControlDefault pageLayout,ITextElement textElement)
{
InitializeComponent();
pPageLayout = pageLayout;
pTextElement = textElement;
pTextSymbol = pTextElement.Symbol;
pGraphicsContainer = pageLayout.ActiveView.GraphicsContainer;
}
private void Properties_Load(object sender, EventArgs e)
{
textBox1.Text = pTextElement.Text;
textBox2.Text = pTextSymbol.Font.Name + " " + pTextSymbol.Font.Size.ToString();
numericUpDown1.Value = (decimal)(pTextSymbol.Angle);
checkB.Checked = pTextSymbol.Font.Bold;
checkU.Checked = pTextSymbol.Font.Underline;
checkI.Checked = pTextSymbol.Font.Italic;
pCharacterOrientation = pTextSymbol as ICharacterOrientation;
checkO.Checked = pCharacterOrientation.CJKCharactersRotation;
}
private void buttonChange_Click(object sender, EventArgs e) //更改字体
{
FontDialog fontDialog = new FontDialog();
if (fontDialog.ShowDialog() == DialogResult.OK)
{
Font selectFont = fontDialog.Font;
textBox2.Text = selectFont.Name + " " + selectFont.Size.ToString();
stdole.IFontDisp pFont = ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(selectFont) as stdole.IFontDisp;
pTextSymbol.Font = pFont;
}
}
private void buttonOK_Click(object sender, EventArgs e) //确定
{
pCharacterOrientation = pTextSymbol as ICharacterOrientation;
pCharacterOrientation.CJKCharactersRotation = checkO.Checked;
stdole.IFontDisp pFont = pTextSymbol.Font;
pFont.Bold = checkB.Checked;
pFont.Underline = checkU.Checked;
pFont.Italic = checkI.Checked;
pTextSymbol.Font = pFont;
pTextElement.Text = textBox1.Text;
pTextElement.Symbol = pTextSymbol;
pGraphicsContainer.UpdateElement(pTextElement as IElement);
pPageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
this.Close();
this.Dispose();
}
private void buttonCancel_Click(object sender, EventArgs e) //取消
{
this.Close();
this.Dispose();
}
}
使用时要在主界面中的Pagelayout空间中编写双击事件,如下
private void axPageLayoutControl1_OnDoubleClick(object sender, IPageLayoutControlEvents_OnDoubleClickEvent e)
{
IElement pelement, selectElement = null;
IGraphicsContainerSelect pGraphicsContainerSelect = pPageLayout.PageLayout as IGraphicsContainerSelect;
IGraphicsContainer pGraphicsContainer = pPageLayout.PageLayout as IGraphicsContainer;
pGraphicsContainer.Reset();
pelement = pGraphicsContainer.Next();
while (pelement != null)
{
if (pelement.HitTest(e.pageX, e.pageY, 0.1))
{
if (pelement is ITextElement)
{
selectElement = pelement;
}
}
pelement = pGraphicsContainer.Next();
}
if (selectElement is ITextElement)
{
Properties propertiesForm = new Properties(pPageLayout, selectElement as ITextElement);
propertiesForm.Visible = true;
}
}
没有做文本元素位置选择的功能,感觉那个作用作用不大,因为位置可以通过Select Element工具调整
来自:https://www.cnblogs.com/caodajieup/archive/2011/09/28/2193891.html