代碼如下,求大佬幫忙看看:
public partial class Form1 : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1());
}
private ITOCControl2 m_tocControl = null;
private IToolbarMenu m_menuMap = null;
private IToolbarMenu m_menuLayer = null;
private IMapControl3 m_mapControl = null;
//private ILayer layer;
//private esriTOCControlItem item;
public Form1()
{
InitializeComponent();
}
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
if (e.button != 2) return;
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (item == esriTOCControlItem.esriTOCControlItemMap)
m_tocControl.SelectItem(map, null);
else
m_tocControl.SelectItem(layer, null);
m_mapControl.CustomProperty = layer;
if (item == esriTOCControlItem.esriTOCControlItemMap)
m_menuMap.PopupMenu(e.x, e.y, m_tocControl.hWnd);
if (item == esriTOCControlItem.esriTOCControlItemLayer)
m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
}
}
}
uj5u.com熱心網友回復:
m_tocControl這個物件沒有new 在構造或者load事件中new一下uj5u.com熱心網友回復:
未將物件參考設定到物件的實體 是沒有實體化,以后碰到這個問題就知道什么意思了uj5u.com熱心網友回復:
m_tocControl=new IMapControl3();m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
uj5u.com熱心網友回復:
我加了這行代碼之后就提示無法創建抽象類或介面“ESRI.ArcGIS.Controls.IMapControl3”的實體 這是怎么回事
uj5u.com熱心網友回復:
IMapControl3 是個介面吧,你第三方還是自己實作了。是不是還有實作類了MapControl3
m_tocControl=new MapControl3();
IMapControl3 是介面
uj5u.com熱心網友回復:
我加了一行 m_tocControl = new TOCControl() as ITOCControl2 ;這個代碼貌似就可以了
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/22817.html
標籤:C#
