C# winform中绘制面

rakushisu 2018-02-03 07:37:56
关于argis的问题, 如何在winform中的地图上绘制一个圆形的阴影区域呢? 类似于百度地图api的Circle区域

private void Test()
{
IGraphicsContainer pGraphicsContainer;
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = axMapControl1.ActiveView;

IGeometry Polygon;
Polygon = axMapControl1.TrackPolygon();
IPolygonElement PolygonElement;
PolygonElement = new PolygonElementClass();

IElement pElement;
pElement = PolygonElement as IElement;
pElement.Geometry = Polygon;// 这里报错: 未将对象引用到对象的实例, Polygon为null
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
pActiveView.Refresh();
}

试着修改了一下, 成了下面的样子, 没有报错,但也没有绘制(这是当然的,因为就没有设置绘制的相关属性)

private void Test()
{
IGraphicsContainer pGraphicsContainer;
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = axMapControl1.ActiveView;

IGeometry Polygon;
Polygon = new PolygonClass();
IPolygonElement PolygonElement;
PolygonElement = new PolygonElementClass();

IElement pElement;
pElement = PolygonElement as IElement;
pElement.Geometry = Polygon;// 这里报错: 未将对象引用到对象的实例, Polygon为null
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
pActiveView.Refresh();
}

然后试着设置Polygon的属性, Demension, Envelope, GeometryType, IsEmpty都是只读属性, 只有一个SpaticalReference是读写属性

Spatical意思是空间, Reference意思应该是引用. 引用空间? 不懂.

试着折腾了一番, 成了下面一堆

private void Test()
{
IGraphicsContainer pGraphicsContainer;
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = axMapControl1.ActiveView;

IGeometry Polygon;
Polygon = new PolygonClass();
Polygon.SpatialReference = axMapControl1.Map as ISpatialReference;
IPolygonElement PolygonElement;
PolygonElement = new PolygonElementClass();

IElement pElement;
pElement = PolygonElement as IElement;
pElement.Geometry = Polygon;// 这里报错: 未将对象引用到对象的实例, Polygon为null
pGraphicsContainer = pMap as IGraphicsContainer;
pGraphicsContainer.AddElement((IElement)PolygonElement, 0);
pActiveView.Refresh();
}

没有办法, 求救!! 需要在空白的axMapControl空间上绘制一个圆形阴影区域, 可以定义圆心和半径, 如果可以的话同时能够定义透明度

...全文
558 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
可以使用GDI绘图
rakushisu 2018-02-21
  • 打赏
  • 举报
回复
过年一直在疯. .. 非常感谢你的回答. 看来自己还是基础不足. 项目这块自己已经不用负责了. 主要是想能扩展一下自己的知识.
  • 打赏
  • 举报
回复
对于 argis 的问题要看它自己的教程。前提是有图形应用开发基础。比如说你不知道
pElement
这里根本没有为变量引用任何对象,这样搞开发继续下去其实就是比较痛苦了。
  • 打赏
  • 举报
回复
随便给你搜一篇文章https://www.cnblogs.com/tsliwei/p/5616381.html 当你设计一个大系统时,如果你的工具决定了你用5年时间都还在纠结最底层的“点线面”的时候,做不了别人用半个月开发出来的东西的时候,那么你就应该选择一个专门用来开发2d-3d图形系统的开发平台来学习,从使用高级的一整套绘图控件开始学习。

110,571

社区成员

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

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

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