AE未将对象引用设置到对象的实例

leeleelilili 2020-07-15 09:28:03
代码如下,求大佬帮忙看看:
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);
}
}
}
...全文
383 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
leeleelilili 2020-07-15
  • 打赏
  • 举报
回复
引用 5 楼 耗子哭死猫 的回复:
IMapControl3 是个接口吧,你第三方还是自己实现了。
是不是还有实现类了MapControl3

m_tocControl=new MapControl3();

IMapControl3 是接口

我加了一行 m_tocControl = new TOCControl() as ITOCControl2 ;这个代码貌似就可以了
耗子哭死猫 2020-07-15
  • 打赏
  • 举报
回复
IMapControl3 是个接口吧,你第三方还是自己实现了。 是不是还有实现类了MapControl3 m_tocControl=new MapControl3(); IMapControl3 是接口
leeleelilili 2020-07-15
  • 打赏
  • 举报
回复
引用 3 楼 耗子哭死猫 的回复:
m_tocControl=new IMapControl3();
m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

我加了这行代码之后就提示无法创建抽象类或接口“ESRI.ArcGIS.Controls.IMapControl3”的实例 这是怎么回事
耗子哭死猫 2020-07-15
  • 打赏
  • 举报
回复
m_tocControl=new IMapControl3(); m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
耗子哭死猫 2020-07-15
  • 打赏
  • 举报
回复
未将对象引用设置到对象的实例 是没有实例化,以后碰到这个问题就知道什么意思了
OrdinaryCoder 2020-07-15
  • 打赏
  • 举报
回复
m_tocControl这个对象没有new 在构造或者load事件中new一下

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧