按MapGIS 10.5 Objects 二次开发演示做完,没有任何显示,
Form1.cs代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MapGIS.GeoMap;
using MapGIS.GISControl;
namespace zfmapgis
{
public partial class Form1 : Form
{
//定义地图显示控件
MapControl mapCtrl = null;
//地图文档对象
Document doc = null;
//地图对象
Map map = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
//实例化地图显示控件
mapCtrl = new MapControl();
//设置地图显示控件的显示模式
mapCtrl.Dock = DockStyle.Fill;
//添加地图显示控件
this.panel1.Controls.Add(this.mapCtrl);
//打开指定地图文档
doc = new Document();
if(doc.Open (@"E:\Program Files\MapGIS 10\Sample\地图文档.mapx") > 0)
{
//获取第一个地图
map = doc.GetMaps().GetMap(0);
if (map!=null)
{
//显示地图
this.mapCtrl.ActiveMap = map;
//复位窗口
this.mapCtrl.Restore();
}
else
{
MessageBox.Show("当前地图文档无地图数据");
return;
}
}
else
{
MessageBox.Show("打开失败!");
}
}
}
}
App.config代码如下:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy ="true">
<supportedRuntime version ="v4.0"/>
</startup>
</configuration>
Form1.Designer.cs代码如下:
namespace zfmapgis
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(800, 232);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
}
}
Program.cs代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace zfmapgis
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
点击“开始调试”后,没有显示界面出现,输出信息如下: