【问题标题】:Selecting a Graphic Element on button click using IGraphicContainerSelect使用 IGraphicContainerSelect 在按钮单击时选择图形元素
【发布时间】: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


    【解决方案1】:

    尝试刷新您的地图。 我认为使用 pLayout.PartialRefresh 或 pScreenDisplay.Invalidate 方法更好。

    pLayout.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection,null,pLayout.Extent)
    

    IScreenDisplay pScreenDisplay = pLayout.ScreenDisplay;
    pScreenDisplay.Invalidate(null,false,esriViewGraphicSelection);
    pScreenDisplay.UpdateWindow();
    

    查看帮助:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//000100000242000000

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 2014-08-30
      相关资源
      最近更新 更多