📄 form1.cs
字号:
//通过使用CustomPolylineMapTool来实现在图上进行距离测量的程序
//程序设计:月光宝盒(by MoonLight)
//完成时间:2005年11月11日
//主要内容:
// 1-使用CustomPloylineMapTool工具来进行地图上的测距
// 2-使用内嵌资源BMP和CUR来对工具条和鼠标来进行样式更改
// 3-使用Windows工具条来进行地图工具的赋予
// 4-使用statusBar显示相关信息
// 5-为地图增加了比例尺修饰,并对其地图单位进行了修改
//说明:
// 地图使用的是国家基础地理信息,坐标系统为经纬度坐标系统
// 程序在VS.NET2003上调试通过
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using MapInfo.Windows.Dialogs;
using MapInfo.Windows.Controls;
using MapInfo.Engine;
using MapInfo.Data;
using MapInfo.Data.Find;
using MapInfo.Styles;
using MapInfo.Mapping;
using MapInfo.Tools;
using MapInfo.Geometry;
namespace CSMapTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private MapInfo.Windows.Controls.MapControl mapControl1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton Separator_1;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private int distCount = 0;//计算距离时点击地图的次数。
private double[,] distxy = new double[50,2];//用于计算距离所使用的存储数据的数组
private int i=0,j=0;//用于所有FOR循环的计数器
private double Dist = 0;//用于测量距离的工具
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.StatusBarPanel statusBarPanel3;
private System.Windows.Forms.ToolBarButton Separator_2;
private System.Windows.Forms.ToolBarButton toolBarTest;
private System.Windows.Forms.ToolBarButton toolBarButton9;
private System.Windows.Forms.ToolBarButton toolBarButton10;
private System.Windows.Forms.ToolBarButton toolBarButton11;
private System.Windows.Forms.ToolBarButton toolBarButton12;
private System.Windows.Forms.ToolBarButton Separator_3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
//将整个数组都初始化为(0,0)
for(i=0;i<50;i++)
for (j=0;j<2;j++)
distxy[i,j]=0;
//以下代码是完成工具条的图片索引的添加
ImageList imList = new ImageList();
imList.ImageSize = new Size(18, 16);
imList.ColorDepth = ColorDepth.Depth4Bit;
imList.TransparentColor = Color.FromArgb(192, 192, 192);
// adds the bitmap
//imList.Images.AddStrip(new Bitmap(@"D:\VisualNet\Mydistance\buttons.bmp"));
imList.Images.AddStrip(new Bitmap(
Assembly.GetExecutingAssembly().GetManifestResourceStream(
this.GetType(), "buttons.bmp")));
toolBar1.ImageList = imList;
toolBarButton1.ImageIndex = 18;
toolBarButton2.ImageIndex = 15;
toolBarButton3.ImageIndex = 16;
toolBarButton4.ImageIndex = 17;
toolBarButton5.ImageIndex = 30;
toolBarButton6.ImageIndex = 31;
toolBarButton7.ImageIndex = 28;
toolBarButton8.ImageIndex = 29;
toolBarButton9.ImageIndex = 10;
toolBarButton10.ImageIndex = 19;
toolBarButton11.ImageIndex = 40;
toolBarButton12.ImageIndex = 43;
toolBarTest.ImageIndex = 47;
//mapControl1的工具使用事件
this.mapControl1.Tools.Used += new MapInfo.Tools.ToolUsedEventHandler(Tools_Used);
//添加自定义工具,CustomPolylineMapTool用于测量距离
mapControl1.Tools.Add("UserDist", new CustomPolylineMapTool(true,true,true,
mapControl1.Viewer, mapControl1.Handle.ToInt32(), mapControl1.Tools,
mapControl1.Tools.MouseToolProperties, mapControl1.Tools.MapToolProperties));
//为地图加上比例尺条
mapControl1.Map.Zoom = new MapInfo.Geometry.Distance(
CoordSys.ConvertDistanceUnits(DistanceUnit.Kilometer,mapControl1.Map.Zoom.Value,mapControl1.Map.Zoom.Unit),
DistanceUnit.Kilometer);
ScaleBarAdornment a = new ScaleBarAdornment(mapControl1.Map);
ScaleBarAdornmentControl ac = new ScaleBarAdornmentControl(a, mapControl1.Map);
ac.Location = new System.Drawing.Point(5,30);
mapControl1.AddAdornment(a, ac);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager mapControl1Resources = new System.Resources.ResourceManager(typeof(CSMapTest.Form1));
MapInfo.Persistence.WorkSpaceLoader mapControl1Loader = new MapInfo.Persistence.WorkSpaceLoader(((System.IO.Stream)(mapControl1Resources.GetObject("mapControl1.Map"))));
this.mapControl1 = new MapInfo.Windows.Controls.MapControl();
this.panel1 = new System.Windows.Forms.Panel();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.Separator_1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.Separator_2 = new System.Windows.Forms.ToolBarButton();
this.toolBarTest = new System.Windows.Forms.ToolBarButton();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel3 = new System.Windows.Forms.StatusBarPanel();
this.toolBarButton9 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton10 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton11 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton12 = new System.Windows.Forms.ToolBarButton();
this.Separator_3 = new System.Windows.Forms.ToolBarButton();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).BeginInit();
this.SuspendLayout();
//
// mapControl1
//
this.mapControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.mapControl1.Location = new System.Drawing.Point(0, 0);
this.mapControl1.Name = "mapControl1";
this.mapControl1.Size = new System.Drawing.Size(692, 481);
this.mapControl1.TabIndex = 0;
this.mapControl1.Text = "mapControl1";
this.mapControl1.DoubleClick += new System.EventHandler(this.mapControl1_DoubleClick);
mapControl1Loader.Load(this.mapControl1.Map);
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.mapControl1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(696, 485);
this.panel1.TabIndex = 1;
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.Separator_1,
this.toolBarButton5,
this.toolBarButton6,
this.toolBarButton7,
this.toolBarButton8,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -