【发布时间】:2014-11-06 22:05:21
【问题描述】:
我在类型转换和使用正确的接口时遇到问题。我有一个函数可以遍历具有特定属性集的所有文本元素。找到匹配项后,我希望能够选择此文本元素或使其处于活动状态或突出显示或地图上的任何内容。代码如下。
protected override void OnClick(Item item)
{
IMxDocument pDoc = ValidateInterface.GetMxDocument();
IActiveView pLayout = (IActiveView)pDoc.PageLayout;
IGraphicsContainer pGraphicsCont = (IGraphicsContainer)pDoc.PageLayout;
pGraphicsCont.Reset();
IElementProperties _ElemProps = null;
while ((_ElemProps = (IElementProperties)pGraphicsCont.Next()) != null)
{
if (_ElemProps.CustomProperty is IPropertySet2)
{
ITextElement _textElement = (ITextElement)_ElemProps;
IPropertySet2 _propertySet = (IPropertySet2)_ElemProps.CustomProperty;
MessageBox.Show("Before I compare item to string");
if (item.Caption == Convert.ToString(_propertySet.GetProperty(NAME_STRING)))
{
//Problems start here
MessageBox.Show("Inside the IF statement");
IGraphicsContainerSelect _SelectMyElement = null; // = (IGraphicsContainerSelect)pGraphicsCont;
ITextElement _newTextElement = (ITextElement)pGraphicsCont;
IElement TestElement = _newTextElement as IElement;
_SelectMyElement.SelectElement(TestElement);
}
}
}
}
虽然在我的地图上没有选择任何内容。我正在遍历地图上的每个图形元素 (IGraphicContainer)。找到匹配项后,我想选择该图形元素。我正在尝试利用 IGraphicContainerSelect 来执行此操作。它需要一个 IElement 变量类型作为参数,这就是我尝试强制转换它的原因。但同样,注意被选中。当我点击一个按钮时,这一切都会发生。
对此的任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: c# casting element containers arcobjects