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