2014-11-06 25 views
0

我遇到了類型轉換和使用正確接口的麻煩。我有一個函數可以遍歷所有具有特定屬性集的文本元素。找到匹配項後,我希望能夠選擇該文本元素或使其處於活動狀態或突出顯示或地圖上的任何內容。下面的代碼。使用IGraphicContainerSelect在點擊按鈕時選擇一個圖形元素

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變量類型作爲參數,因此我試圖將其轉換。但是,再次注意到正在被選中。這一切都發生在我點擊一個按鈕時。

任何幫助,將不勝感激。提前致謝。

回答

0

嘗試刷新您的地圖。 我認爲使用pLayout.PartialRefresh或pScreenDisplay.Invalidate方法的方法更好。

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

OR

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

相關問題