• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • C#中調用mapx5.0

    發表于:2007-05-25來源:作者:點擊數: 標簽:mapx5.0我在這是.NET環境
    這是 我在 .net 環境中調用mapx5.0控件 的一次test,前幾次網上沒有發現這方面的文章,所以自己 把幾個代碼拿出 來:這里有些代碼是自動生成的,但只要把幾篇文章的代碼直接拷貝到工程里 就 能直接運行的。 using System.Drawing; using System.Collections;
    這是 我在.net環境中調用mapx5.0控件 的一次test,前幾次網上沒有發現這方面的文章,所以自己
    把幾個代碼拿出 來:這里有些代碼是自動生成的,但只要把幾篇文章的代碼直接拷貝到工程里 就
    能直接運行的。


    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;


    namespace gistestbymyself
    {
    /// <summary>
    /// Form1 的摘要說明。
    /// </summary>
    public class FrmMain : System.Windows.Forms.Form
    {


    #region 私有變量的聲明
    private AxMapXLib.AxMap axMap1;
    private AxMapXLib.AxMap axMap2;


    private double zoom;
    private double centerx;
    private double centery;
    #endregion


    #region Windows 窗體上拖入窗體的控件
    /// <summary>
    ///
    /// 窗體信息。
    /// </summary>




    private System.Windows.Forms.ToolBar toolBar2;
    private System.Windows.Forms.ToolBarButton tbfangda;
    private System.Windows.Forms.ToolBarButton tbbianxiao;
    private System.Windows.Forms.ToolBarButton tbmanyou;
    private System.Windows.Forms.ToolBarButton tbbiaozhu;
    private System.Windows.Forms.ToolBarButton tbjuli;
    private System.Windows.Forms.ToolBarButton tbshuaxin;
    private System.Windows.Forms.ToolBarButton tbxiangxi;
    private System.Windows.Forms.ToolBarButton tbzuiduan;
    private System.Windows.Forms.ToolBarButton tbmianji;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.ToolBarButton tbxuanze;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem menuItem2;
    private System.Windows.Forms.MenuItem menuItem3;
    private System.Windows.Forms.MenuItem mutuceng;
    private System.Windows.Forms.ContextMenu comu;
    private System.Windows.Forms.MenuItem menuItem4;
    private System.Windows.Forms.MenuItem menuItem5;
    private System.Windows.Forms.MenuItem menuItem6;
    private System.Windows.Forms.MenuItem menuItem7;
    private System.Windows.Forms.ContextMenu comu1;
    private System.Windows.Forms.MenuItem menuItem8;
    private System.Windows.Forms.MenuItem menuItem9;
    private System.Windows.Forms.ToolBarButton tbtianjiafuhao;
    private System.Windows.Forms.MenuItem menuItem10;
    private System.Windows.Forms.MenuItem menuItem11;
    private System.Windows.Forms.MenuItem menuItem12;
    private System.Windows.Forms.MenuItem menuItem13;
    private System.Windows.Forms.MenuItem menuItem14;
    private System.Windows.Forms.MenuItem menuItem15;
    private System.Windows.Forms.MenuItem menuItem16;
    private System.Windows.Forms.MenuItem menuItem17;
    private System.Windows.Forms.MenuItem menuItem18;
    private System.Windows.Forms.MenuItem menuItem19;
    private System.Windows.Forms.MenuItem menuItem20;
    private System.Windows.Forms.MenuItem menuItem21;
    private System.Windows.Forms.MenuItem menuItem22;
    private System.Windows.Forms.MenuItem menuItem23;
    private System.Windows.Forms.MenuItem menuItem24;
    private System.Windows.Forms.MenuItem menuItem25;
    private System.Windows.Forms.MenuItem menuItem26;
    private System.Windows.Forms.Splitter splitter1;
    private System.Windows.Forms.MenuItem menuItem27;
    private System.Windows.Forms.ToolBar toolBar1;
    private System.Windows.Forms.ToolBarButton tbadddian;
    private System.Windows.Forms.ToolBarButton tbaddxian;
    private System.Windows.Forms.ToolBarButton tbaddquxian;
    private System.Windows.Forms.ToolBarButton tbaddqumian;
    private System.Windows.Forms.ToolBarButton tbshezhi;
    private System.Windows.Forms.ToolBarButton tbline;
    private System.Windows.Forms.MenuItem menuItem28;
    private System.Windows.Forms.MenuItem menuItem29;
    private System.Windows.Forms.MenuItem menuItem30;
    private System.Windows.Forms.MenuItem menuItem31;
    private System.Windows.Forms.MenuItem menuItem32;
    private System.Windows.Forms.MenuItem menuItem33;
    private System.Windows.Forms.MenuItem menuItem34;
    private System.Windows.Forms.MenuItem menuItem35;
    /// <summary>
    /// 必需的設計器變量。
    /// </summary>
    private System.ComponentModel.Container components = null;


    #endregion


    #region FrmMain類的初始化和Form_Load時發生時的動作


    public FrmMain()
    {
    //
    // Windows 窗體設計器支持所必需的
    //
    InitializeComponent();


    //
    // TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
    //
    this.zoom=axMap1.Zoom; //取得初始化時的地圖比例
    this.centerx=axMap1.CenterX;
    this.centery=axMap1.CenterY; //取得初始化時的地圖坐標,供刷新時使用


    axMap1.CreateCustomTool(10,MapXLib.ToolTypeConstants.miToolTypePoly,MapXLib.CursorConstants.miCrossCursor,null,null,false);
    //創建距離工具


    axMap1.CreateCustomTool(11,MapXLib.ToolTypeConstants.miToolTypePolygon,MapXLib.CursorConstants.miCrossCursor,null,null,false);
    //創建面積工具


    }
    //*********************************
    private void Form1_Load(object sender, System.EventArgs e)
    {

    axMap1.GeoSet=@"D:\....\CHINA.GST";

    axMap2.GeoSet= Directory.GetCurrentDirectory()+ @"\....\*.gst";


    axMap1.TitleText="中國";
    axMap2.TitleText="***";
    }


    #endregion
    //*****************************


    #region Windows 窗體設計器生成的代碼
    /// <summary>
    /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
    /// 此方法的內容。
    /// </summary>
    /// <summary>
    /// 清理所有正在使用的資源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }



    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmMain));
    this.axMap1 = new AxMapXLib.AxMap();
    this.axMap2 = new AxMapXLib.AxMap();
    this.toolBar2 = new System.Windows.Forms.ToolBar();
    this.tbxuanze = new System.Windows.Forms.ToolBarButton();
    this.tbfangda = new System.Windows.Forms.ToolBarButton();
    this.tbbianxiao = new System.Windows.Forms.ToolBarButton();
    this.tbmanyou = new System.Windows.Forms.ToolBarButton();
    this.tbbiaozhu = new System.Windows.Forms.ToolBarButton();
    this.tbtianjiafuhao = new System.Windows.Forms.ToolBarButton();
    this.tbjuli = new System.Windows.Forms.ToolBarButton();
    this.tbmianji = new System.Windows.Forms.ToolBarButton();
    this.tbshuaxin = new System.Windows.Forms.ToolBarButton();
    this.tbxiangxi = new System.Windows.Forms.ToolBarButton();
    this.tbzuiduan = new System.Windows.Forms.ToolBarButton();
    this.label1 = new System.Windows.Forms.Label();
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.menuItem1 = new System.Windows.Forms.MenuItem();
    this.menuItem20 = new System.Windows.Forms.MenuItem();
    this.menuItem21 = new System.Windows.Forms.MenuItem();
    this.menuItem22 = new System.Windows.Forms.MenuItem();
    this.menuItem23 = new System.Windows.Forms.MenuItem();
    this.menuItem24 = new System.Windows.Forms.MenuItem();
    this.menuItem25 = new System.Windows.Forms.MenuItem();
    this.menuItem26 = new System.Windows.Forms.MenuItem();
    this.menuItem2 = new System.Windows.Forms.MenuItem();
    this.menuItem3 = new System.Windows.Forms.MenuItem();
    this.menuItem29 = new System.Windows.Forms.MenuItem();
    this.menuItem28 = new System.Windows.Forms.MenuItem();
    this.menuItem27 = new System.Windows.Forms.MenuItem();
    this.menuItem15 = new System.Windows.Forms.MenuItem();
    this.menuItem32 = new System.Windows.Forms.MenuItem();
    this.menuItem31 = new System.Windows.Forms.MenuItem();
    this.mutuceng = new System.Windows.Forms.MenuItem();
    this.menuItem30 = new System.Windows.Forms.MenuItem();
    this.menuItem16 = new System.Windows.Forms.MenuItem();
    this.menuItem10 = new System.Windows.Forms.MenuItem();
    this.menuItem11 = new System.Windows.Forms.MenuItem();
    this.menuItem12 = new System.Windows.Forms.MenuItem();
    this.menuItem13 = new System.Windows.Forms.MenuItem();
    this.menuItem14 = new System.Windows.Forms.MenuItem();
    this.menuItem17 = new System.Windows.Forms.MenuItem();
    this.menuItem18 = new System.Windows.Forms.MenuItem();
    this.menuItem19 = new System.Windows.Forms.MenuItem();
    this.comu = new System.Windows.Forms.ContextMenu();
    this.menuItem4 = new System.Windows.Forms.MenuItem();
    this.menuItem5 = new System.Windows.Forms.MenuItem();
    this.menuItem6 = new System.Windows.Forms.MenuItem();
    this.menuItem7 = new System.Windows.Forms.MenuItem();
    this.comu1 = new System.Windows.Forms.ContextMenu();
    this.menuItem8 = new System.Windows.Forms.MenuItem();
    this.menuItem9 = new System.Windows.Forms.MenuItem();
    this.splitter1 = new System.Windows.Forms.Splitter();
    this.toolBar1 = new System.Windows.Forms.ToolBar();
    this.tbadddian = new System.Windows.Forms.ToolBarButton();
    this.tbaddxian = new System.Windows.Forms.ToolBarButton();
    this.tbaddquxian = new System.Windows.Forms.ToolBarButton();
    this.tbaddqumian = new System.Windows.Forms.ToolBarButton();
    this.tbline = new System.Windows.Forms.ToolBarButton();
    this.tbshezhi = new System.Windows.Forms.ToolBarButton();
    this.menuItem33 = new System.Windows.Forms.MenuItem();
    this.menuItem34 = new System.Windows.Forms.MenuItem();
    this.menuItem35 = new System.Windows.Forms.MenuItem();
    ((System.ComponentModel.ISupportInitialize)(this.axMap1)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.axMap2)).BeginInit();
    this.SuspendLayout();
    //
    // axMap1
    //
    this.axMap1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    | System.Windows.Forms.AnchorStyles.Left)
    | System.Windows.Forms.AnchorStyles.Right)));
    this.axMap1.Enabled = true;
    this.axMap1.Location = new System.Drawing.Point(8, 120);
    this.axMap1.Name = "axMap1";
    this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState")));
    this.axMap1.Size = new System.Drawing.Size(424, 339);
    this.axMap1.TabIndex = 0;
    this.axMap1.PolyToolUsed += new AxMapXLib.CMapXEvents_PolyToolUsedEventHandler(this.mapMain_PolyToolUsed);
    this.axMap1.MouseUpEvent += new AxMapXLib.CMapXEvents_MouseUpEventHandler(this.axMap1_MouseUpEvent);
    this.axMap1.ThemeModifyRequested += new AxMapXLib.CMapXEvents_ThemeModifyRequestedEventHandler(this.axMap1_ThemeModifyRequested);
    this.axMap1.MouseDownEvent += new AxMapXLib.CMapXEvents_MouseDownEventHandler(this.axMap1_MouseDownEvent);
    this.axMap1.MapViewChanged += new System.EventHandler(this.axMap1_MapViewChanged);
    //
    // axMap2
    //
    this.axMap2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    | System.Windows.Forms.AnchorStyles.Left)
    | System.Windows.Forms.AnchorStyles.Right)));
    this.axMap2.Enabled = true;
    this.axMap2.Location = new System.Drawing.Point(472, 136);
    this.axMap2.Name = "axMap2";
    this.axMap2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap2.OcxState")));
    this.axMap2.Size = new System.Drawing.Size(240, 203);
    this.axMap2.TabIndex = 1;
    //
    // toolBar2
    //
    this.toolBar2.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
    this.tbxuanze,
    this.tbfangda,
    this.tbbianxiao,
    this.tbmanyou,
    this.tbbiaozhu,
    this.tbtianjiafuhao,
    this.tbjuli,
    this.tbmianji,
    this.tbshuaxin,
    this.tbxiangxi,
    this.tbzuiduan});
    this.toolBar2.ButtonSize = new System.Drawing.Size(55, 35);
    this.toolBar2.DropDownArrows = true;
    this.toolBar2.Location = new System.Drawing.Point(0, 0);
    this.toolBar2.Name = "toolBar2";
    this.toolBar2.ShowToolTips = true;
    this.toolBar2.Size = new System.Drawing.Size(776, 41);
    this.toolBar2.TabIndex = 3;
    this.toolBar2.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar2_ButtonClick);
    //
    // tbxuanze
    //
    this.tbxuanze.Text = "選擇";
    //
    // tbfangda
    //
    this.tbfangda.Text = "放大";
    this.tbfangda.ToolTipText = "放大";
    //
    // tbbianxiao
    //
    this.tbbianxiao.Text = "縮小";
    //
    // tbmanyou
    //
    this.tbmanyou.Text = "漫游";
    //
    // tbbiaozhu
    //
    this.tbbiaozhu.Text = "標注";
    //
    // tbtianjiafuhao
    //
    this.tbtianjiafuhao.Text = "添加符號";
    //
    // tbjuli
    //
    this.tbjuli.Text = "測距";
    //
    // tbmianji
    //
    this.tbmianji.Text = "面積";
    //
    // tbshuaxin
    //
    this.tbshuaxin.Text = "刷新";
    //
    // tbxiangxi
    //
    this.tbxiangxi.Text = "詳細";
    //
    // tbzuiduan
    //
    this.tbzuiduan.Text = "最短實體";
    //
    // label1
    //
    this.label1.Location = new System.Drawing.Point(48, 104);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(208, 16);
    this.label1.TabIndex = 4;
    this.label1.Text = "label1";
    //
    // mainMenu1
    //
    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem1,
    this.menuItem3,
    this.menuItem10,
    this.menuItem17,
    this.menuItem18});
    //
    // menuItem1
    //
    this.menuItem1.Index = 0;
    this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem20,
    this.menuItem21,
    this.menuItem22,
    this.menuItem23,
    this.menuItem24,
    this.menuItem25,
    this.menuItem26,
    this.menuItem33,
    this.menuItem35,
    this.menuItem34,
    this.menuItem2});
    this.menuItem1.Text = "文件";
    //
    // menuItem20
    //
    this.menuItem20.Index = 0;
    this.menuItem20.Text = "打開地圖...";
    this.menuItem20.Click += new System.EventHandler(this.menuItem20_Click);
    //
    // menuItem21
    //
    this.menuItem21.Index = 1;
    this.menuItem21.Text = "添加圖層...";
    this.menuItem21.Click += new System.EventHandler(this.menuItem21_Click);
    //
    // menuItem22
    //
    this.menuItem22.Index = 2;
    this.menuItem22.Text = "-";
    //
    // menuItem23
    //
    this.menuItem23.Index = 3;
    this.menuItem23.Text = "保存";
    this.menuItem23.Click += new System.EventHandler(this.menuItem23_Click);
    //
    // menuItem24
    //
    this.menuItem24.Index = 4;
    this.menuItem24.Text = "另存為...";
    this.menuItem24.Click += new System.EventHandler(this.menuItem24_Click);
    //
    // menuItem25
    //
    this.menuItem25.Index = 5;
    this.menuItem25.Text = "導出..";
    this.menuItem25.Click += new System.EventHandler(this.menuItem25_Click);
    //
    // menuItem26
    //
    this.menuItem26.Index = 6;
    this.menuItem26.Text = "-";
    //
    // menuItem2
    //
    this.menuItem2.Index = 10;
    this.menuItem2.Text = "退出";
    //
    // menuItem3
    //
    this.menuItem3.Index = 1;
    this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem29,
    this.menuItem28,
    this.menuItem27,
    this.menuItem15,
    this.menuItem32,
    this.menuItem31,
    this.mutuceng,
    this.menuItem30,
    this.menuItem16});
    this.menuItem3.Text = "地圖";
    //
    // menuItem29
    //
    this.menuItem29.Index = 0;
    this.menuItem29.Text = "坐標變換(投影)";
    this.menuItem29.Click += new System.EventHandler(this.menuItem29_Click);
    //
    // menuItem28
    //
    this.menuItem28.Index = 1;
    this.menuItem28.Text = "-";
    //
    // menuItem27
    //
    this.menuItem27.Index = 2;
    this.menuItem27.Text = "編輯";
    this.menuItem27.Click += new System.EventHandler(this.menuItem27_Click);
    //
    // menuItem15
    //
    this.menuItem15.Index = 3;
    this.menuItem15.Text = "-";
    //
    // menuItem32
    //
    this.menuItem32.Index = 4;
    this.menuItem32.Text = "縮放圖層";
    this.menuItem32.Click += new System.EventHandler(this.menuItem32_Click);
    //
    // menuItem31
    //
    this.menuItem31.Index = 5;
    this.menuItem31.Text = "選擇圖層";
    this.menuItem31.Click += new System.EventHandler(this.menuItem31_Click);
    //
    // mutuceng
    //
    this.mutuceng.Index = 6;
    this.mutuceng.Text = "圖層控制";
    this.mutuceng.Click += new System.EventHandler(this.mutuceng_Click);
    //
    // menuItem30
    //
    this.menuItem30.Index = 7;
    this.menuItem30.Text = "-";
    //
    // menuItem16
    //
    this.menuItem16.Index = 8;
    this.menuItem16.Text = "屬性";
    this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click);
    //
    // menuItem10
    //
    this.menuItem10.Index = 2;
    this.menuItem10.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem11,
    this.menuItem12,
    this.menuItem13,
    this.menuItem14});
    this.menuItem10.Text = "注釋";
    //
    // menuItem11
    //
    this.menuItem11.Index = 0;
    this.menuItem11.Text = "添加符號";
    this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
    //
    // menuItem12
    //
    this.menuItem12.Index = 1;
    this.menuItem12.Text = "添加文本";
    this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
    //
    // menuItem13
    //
    this.menuItem13.Index = 2;
    this.menuItem13.Text = "移除";
    this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
    //
    // menuItem14
    //
    this.menuItem14.Index = 3;
    this.menuItem14.Text = "設置";
    this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
    //
    // menuItem17
    //
    this.menuItem17.Index = 3;
    this.menuItem17.Text = "窗口";
    //
    // menuItem18
    //
    this.menuItem18.Index = 4;
    this.menuItem18.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem19});
    this.menuItem18.Text = "幫助";
    //
    // menuItem19
    //
    this.menuItem19.Index = 0;
    this.menuItem19.Text = "關于MapX";
    this.menuItem19.Click += new System.EventHandler(this.menuItem19_Click);
    //
    // comu
    //
    this.comu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem4,
    this.menuItem5,
    this.menuItem6,
    this.menuItem7});
    //
    // menuItem4
    //
    this.menuItem4.Index = 0;
    this.menuItem4.Text = "普通";
    this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
    //
    // menuItem5
    //
    this.menuItem5.Index = 1;
    this.menuItem5.Text = "矩形";
    this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
    //
    // menuItem6
    //
    this.menuItem6.Index = 2;
    this.menuItem6.Text = "圓形";
    this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
    //
    // menuItem7
    //
    this.menuItem7.Index = 3;
    this.menuItem7.Text = "多邊形";
    this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
    //
    // comu1
    //
    this.comu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    this.menuItem8,
    this.menuItem9});
    //
    // menuItem8
    //
    this.menuItem8.Index = 0;
    this.menuItem8.Text = "添加符號";
    this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
    //
    // menuItem9
    //
    this.menuItem9.Index = 1;
    this.menuItem9.Text = "添加";
    this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
    //
    // splitter1
    //
    this.splitter1.Location = new System.Drawing.Point(0, 41);
    this.splitter1.Name = "splitter1";
    this.splitter1.Size = new System.Drawing.Size(3, 432);
    this.splitter1.TabIndex = 5;
    this.splitter1.TabStop = false;
    //
    // toolBar1
    //
    this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
    this.tbadddian,
    this.tbaddxian,
    this.tbaddquxian,
    this.tbaddqumian,
    this.tbline,
    this.tbshezhi});
    this.toolBar1.Dock = System.Windows.Forms.DockStyle.None;
    this.toolBar1.DropDownArrows = true;
    this.toolBar1.Location = new System.Drawing.Point(0, 40);
    this.toolBar1.Name = "toolBar1";
    this.toolBar1.ShowToolTips = true;
    this.toolBar1.Size = new System.Drawing.Size(488, 28);
    this.toolBar1.TabIndex = 6;
    this.toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
    this.toolBar1.Visible = false;
    this.toolBar1.Wrappable = false;
    this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
    //
    // tbadddian
    //
    this.tbadddian.Text = "點 ";
    this.tbadddian.Visible = false;
    //
    // tbaddxian
    //
    this.tbaddxian.Text = "線 ";
    this.tbaddxian.Visible = false;
    //
    // tbaddquxian
    //
    this.tbaddquxian.Text = "曲線 ";
    this.tbaddquxian.Visible = false;
    //
    // tbaddqumian
    //
    this.tbaddqumian.Text = "面 ";
    this.tbaddqumian.Visible = false;
    //
    // tbline
    //
    this.tbline.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
    //
    // tbshezhi
    //
    this.tbshezhi.Text = "設置 ";
    this.tbshezhi.Visible = false;
    //
    // menuItem33
    //
    this.menuItem33.Index = 7;
    this.menuItem33.Text = "打印設置";
    //
    // menuItem34
    //
    this.menuItem34.Index = 9;
    this.menuItem34.Text = "-";
    //
    // menuItem35
    //
    this.menuItem35.Index = 8;
    this.menuItem35.Text = "打印...";
    //
    // FrmMain
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(776, 473);
    this.Controls.Add(this.toolBar1);
    this.Controls.Add(this.splitter1);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.toolBar2);
    this.Controls.Add(this.axMap2);
    this.Controls.Add(this.axMap1);
    this.Menu = this.mainMenu1;
    this.Name = "FrmMain";
    this.Text = "FrmMain";
    this.Load += new System.EventHandler(this.Form1_Load);
    ((System.ComponentModel.ISupportInitialize)(this.axMap1)).EndInit();
    ((System.ComponentModel.ISupportInitialize)(this.axMap2)).EndInit();
    this.ResumeLayout(false);


    }
    #endregion


    #region 應用程序的主入口點
    /// <summary>
    /// 應用程序的主入口點。
    /// </summary>
    [STAThread]
    static void Main()
    {
    FrmMain FMain;
    Application.Run(FMain=new FrmMain());
    }
    #endregion


    //****************************************
    #region axMap1對象的屬性操作,一般都在其他窗口里被使用
    /// <summary>
    /// 在這里適用屬性主要是為了axMap1這個私有的對象能在其他窗體中獲得一些需要的改變
    /// </summary>
    ///
    //屬性1
    public MapXLib.Style SyStyle //屬性操作,設置或取得符號的樣式,在 Frmannotation 中使用了該屬性,
    {
    set
    {
    axMap1.DefaultStyle=value;
    }
    get
    {
    return axMap1.DefaultStyle;
    }
    }
    //屬性2
    public MapXLib.Style editStyle //屬性操作,設置或取得在編輯圖層時,改變的點,線和曲面的樣式 在Frmeditable
    {
    set //中使用了該屬性,
    {
    axMap1.AutoRedraw=true;
    axMap1.Layers.InsertionLayer.Style=value;
    }
    get
    {
    axMap1.Layers.InsertionLayer.OverrideStyle=true;
    axMap1.AutoRedraw=false;
    return axMap1.Layers.InsertionLayer.Style;
    }
    }
    //屬性3
    public MapXLib.Layers Layer //屬性操作,通過該屬性,圖層選擇顯示窗口(FrmViewLyr)可以操作axMap1的Layers屬性,
    { //在FrmViewLyr_Load 時可以得到 Layers
    get
    {
    return axMap1.Layers;
    }


    }
    //屬性4
    public string LyrName //屬性操作,通過該屬性,得到圖層選擇顯示窗口(FrmViewLyr)中cobLyr.text中的值
    { //來顯示那個圖層將被顯示
    set
    {
    if(value=="All Layers")
    axMap1.CtlBounds=axMap1.Layers.Bounds; //注意,這里使用CtlBounds屬性(MapX的屬性),而不是Bounds(.net本身的屬性)在.net
    else
    axMap1.CtlBounds=axMap1.Layers[value].Bounds; //環境下,有點改變,


    }
    }


    #endregion


    //***********************************
    #region 工具條,里面包含選擇、拖動漫游、放大縮小等一些工具


    private void toolBar2_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {
    try
    {


    if(e.Button==tbfangda)
    axMap1.CurrentTool=MapXLib.ToolConstants.miZoomInTool;//1003
    if(e.Button==tbbianxiao)
    axMap1.CurrentTool=MapXLib.ToolConstants.miZoomOutTool;//縮小地圖
    if(e.Button==tbmanyou)
    axMap1.CurrentTool=MapXLib.ToolConstants.miPanTool;//漫游地圖
    if(e.Button==tbbiaozhu) //標注地圖
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miLabelTool;


    //Point p=new Point(20+55*5,20);
    //comu1.Show(toolBar2,p);


    }
    if(e.Button==tbtianjiafuhao)
    axMap1.CurrentTool=MapXLib.ToolConstants.miSymbolTool;
    if(e.Button==tbjuli)
    axMap1.CurrentTool=( MapXLib.ToolConstants ) 10;
    if(e.Button==tbmianji)
    axMap1.CurrentTool=(MapXLib.ToolConstants ) 11;
    if(e.Button==tbshuaxin)
    {
    //刷新地圖,回到初始狀態
    axMap1.ZoomTo(this.zoom,this.centerx,this.centery); //恢復初始時的比例
    //axMap1.Annotations.RemoveAll();
    axMap1.Refresh();
    }
    if(e.Button==tbxuanze)
    {
    Point p=new Point(20,20);
    comu.Show(toolBar2,p); //顯示選擇工具菜單,它允許選擇矩形,圓形,多邊形等
    }



    }
    catch(Exception e1)
    {
    MessageBox.Show(e1.Message);
    }
    }


    #endregion






    接著第一篇文章,繼續,這是在FrMain.cs文件中除了第一篇文章里的代碼外的第二部分:
    //*******************************


    #region 創建自定義工具,用來測量距離(可以折線)和測量面積
    //****************************888
    private void mapMain_PolyToolUsed(object sender, AxMapXLib.CMapXEvents_PolyToolUsedEvent e) //在創建好自己定義的工具后,會根據工具ID來選擇執行


    {


    if(e.toolNum == 10)//測量距離,這是自定義工具,測量多點的距離


    {


    MapXLib.Points pts = (MapXLib.Points)e.points;


    MapXLib.Point pt1,pt2;


    double d=0.0;


    //計算順序兩個點距離,累計得到總距離


    for(int i=1;i<pts.Count;i++)


    {


    pt1=pts._Item(i);


    pt2=pts._Item(i+1);


    d += axMap1.Distance(pt1.X,pt1.Y,pt2.X,pt2.Y);


    }


    label1.Text="距離:" + d.ToString();


    }


    else if(e.toolNum == 11) //面積,這是自定義工具,這里借用了某位網友的文章,謝謝


    {


    MapXLib.Points pts = (MapXLib.Points)e.points;


    MapXLib.FeatureFactory dd = axMap1.FeatureFactory;


    MapXLib.Style style = axMap1.DefaultStyle;


    label1.Text="面積:" + dd.CreateRegion(pts,style).Area.ToString();


    }


    }
    #endregion
    //*******************************


    private void axMap1_MapViewChanged(object sender, System.EventArgs e) //在地圖大小改變時,顯示出比例
    {
    label1.Text=axMap1.Zoom.ToString();
    }


    //*******************************
    private void mutuceng_Click(object sender, System.EventArgs e) //菜單按鈕事件,顯示圖層控制面板
    {
    axMap1.Layers.LayersDlg(null,null);
    }


    private void menuItem31_Click(object sender, System.EventArgs e) //菜單按鈕事件,顯示圖層圖層選擇顯示窗口
    {
    FrmViewLyr frm=new FrmViewLyr();
    frm.Owner=this;
    frm.ShowDialog();
    }
    private void menuItem32_Click(object sender, System.EventArgs e) //菜單按鈕事件,在新窗口中控制圖層的顯示比例等,
    {
    #region 新窗口中控制圖層的顯示比例,此處是省略代碼
    //***********此處省略,主要使用到的是 MapUnit 和MapZoom *******************
    //此處是偽代碼,是mapx5.0的示例程序的vb代碼,和上面的大同小異
    //
    // ZoomText.Text = fMainForm.Map1.Zoom

    // '' Set the unit combo box to the current unit

    // '' Take a short cut: units # 0 through 13 correspond to combo list number

    // If fMainForm.Map1.MapUnit < 14 Then

    // UnitCombo.ListIndex = fMainForm.Map1.MapUnit


    // Else


    // Select Case fMainForm.Map1.MapUnit


    // Case miUnitLink

    // UnitCombo.ListIndex = 14

    // Case miUnitChain


    // UnitCombo.ListIndex = 15

    // Case miUnitRod


    // UnitCombo.ListIndex = 16


    // End Select


    // End If


    // '' Save the current parameters so that the view can be


    // '' restored if "cancel" is pressed


    // OldZoom = fMainForm.Map1.Zoom

    // OldUnit = fMainForm.Map1.MapUnit
    #endregion

    }
    //*******************************
    private void axMap1_ThemeModifyRequested(object sender, AxMapXLib.CMapXEvents_ThemeModifyRequestedEvent e)
    {
    //e.theme
    }


    private void axMap1_MouseDownEvent(object sender, AxMapXLib.CMapXEvents_MouseDownEvent e)
    {
    //e.button=
    }


    private void menuItem4_Click(object sender, System.EventArgs e) //菜單按鈕事件,普通選擇地圖
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miSelectTool;
    menuItem4.RadioCheck=true;
    }


    private void menuItem5_Click(object sender, System.EventArgs e) //菜單按鈕事件,長方形選擇地圖
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miRectSelectTool;
    menuItem5.RadioCheck=true;
    }


    private void menuItem6_Click(object sender, System.EventArgs e) //菜單按鈕事件,圓形選擇地圖
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miRadiusSelectTool;
    menuItem6.RadioCheck=true;
    }


    private void menuItem7_Click(object sender, System.EventArgs e)
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miPolygonSelectTool; //菜單按鈕事件,多邊形選擇地圖
    menuItem7.RadioCheck=true;
    }


    private void menuItem8_Click(object sender, System.EventArgs e)
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miLabelTool; //菜單按鈕事件,直線標注地圖
    }


    private void menuItem9_Click(object sender, System.EventArgs e)
    {
    //axMap1.CurrentTool=MapXLib.ToolConstants. ; //菜單按鈕事件,折線標注地圖
    }


    private void menuItem11_Click(object sender, System.EventArgs e)
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miSymbolTool; //菜單按鈕事件,創建工具,可以在地圖上添加符號,其實是對 mapx 的 Annotations 操作
    }


    private void menuItem12_Click(object sender, System.EventArgs e)
    {
    axMap1.CurrentTool=MapXLib.ToolConstants.miTextTool; //菜單按鈕事件,創建工具,可以在地圖上添加文本,其實是對 mapx 的 Annotations 操作
    }


    private void menuItem13_Click(object sender, System.EventArgs e)
    {
    axMap1.Annotations.RemoveAll(); // 把注釋信息全部移除, 其實是對 mapx 的 Annotations 操作
    }


    private void menuItem14_Click(object sender, System.EventArgs e)
    {
    gistestbymyself.Frmannotation frm=new Frmannotation( axMap1.DefaultStyle.Clone() );
    frm.Owner=this;
    frm.ShowDialog(); // //未完成的,參見D:\Program Files\MapInfo\MapX 5.0\Samples50\VisualBasic\VB5Sample
    }


    private void menuItem16_Click(object sender, System.EventArgs e) //菜單按鈕事件,顯示屬性窗口
    {
    axMap1.PropertyPage();
    }


    private void menuItem19_Click(object sender, System.EventArgs e) //顯示mapx的關于對話框
    {
    axMap1.AboutBox();
    }


    private void menuItem29_Click(object sender, System.EventArgs e) //菜單按鈕事件,調用窗口,對地圖的坐標進行改變,或叫投影
    {
    axMap1.DisplayCoordSys.PickCoordSys(null,null);
    axMap1.NumericCoordSys=axMap1.DisplayCoordSys;
    }


    private void axMap1_MouseUpEvent(object sender, AxMapXLib.CMapXEvents_MouseUpEvent e) //鼠標事件,點擊右鍵,彈出屬性框
    {
    if(e.button==2)
    axMap1.PropertyPage();
    }





    接下來:
    //******************************
    #region 文件/打開*另存為*導出*按鈕的代碼


    private void menuItem20_Click(object sender, System.EventArgs e) //打開地圖文件(*.gst)(模式對話框)
    {
    OpenFileDialog openFD=new OpenFileDialog();
    openFD.Title="打開地圖"; //
    openFD.DefaultExt=".gst";
    openFD.FileName="";
    openFD.Filter="Geoset Files (*.gst)|*.gst";
    if(openFD.ShowDialog()==DialogResult.OK)
    if( (openFD.OpenFile() )!=null )
    {
    axMap1.GeoSet=openFD.FileName; //這里存在已各bug,就是當可編輯工具可見時,能打開地圖,再點擊編輯按鈕時,
    //會出現錯誤;回避這個錯誤,請先點擊"取消編輯".
    }

    }
    private void menuItem21_Click(object sender, System.EventArgs e) //打開圖層文件(*.tab)(模式對話框)
    {
    OpenFileDialog openFD=new OpenFileDialog();
    openFD.Title="打開圖層";
    openFD.DefaultExt=".tab";
    openFD.FileName="";
    openFD.Filter="MapInfo Tables (*.tab)|*.tab";
    if(openFD.ShowDialog()==DialogResult.OK)
    if( (openFD.OpenFile() )!=null )
    {
    axMap1.Layers.Add(openFD.FileName,0);

    }

    }
    private void menuItem23_Click(object sender, System.EventArgs e) //保存按鈕,保存為 *.gst 形式
    {
    if(MessageBox.Show("確定要保存嗎?","OK or nor",MessageBoxButtons.YesNo)==DialogResult.OK)
    axMap1.SaveMapAsGeoset(axMap1.TitleText,axMap1.GeoSet);

    }


    private void menuItem24_Click(object sender, System.EventArgs e) //另存為... *.gst 形式
    {
    SaveFileDialog saveFD =new SaveFileDialog();
    saveFD.Title="保存地圖";
    saveFD.FileName="";
    saveFD.Filter="Geoset Files (*.gst)|*.gst";
    if(saveFD.ShowDialog()==DialogResult.OK)
    if( (saveFD.OpenFile() )!=null )
    {
    try
    {

    axMap1.SaveMapAsGeoset("",saveFD.FileName); //這里有錯誤,不能保存?。。。。。。。。。。?!
    }
    catch(Exception e1)
    {
    MessageBox.Show(e1.Message);
    }

    }

    }


    private void menuItem25_Click(object sender, System.EventArgs e) //到處地圖,可以 以各種圖像的形式到出地圖
    {
    //string ExFmtStr1=.ToString();


    SaveFileDialog exportFD =new SaveFileDialog();
    exportFD.Title="保存地圖";
    exportFD.FileName="";
    exportFD.Filter= "windows bitmap(*.bmp)|*.bmp";
    if(exportFD.ShowDialog()==DialogResult.OK)
    if( (exportFD.OpenFile() )!=null )
    {
    try
    { //MapXLib.ExportFormatConstants.miFormatBMP
    axMap1.ExportMap(exportFD.FileName,MapXLib.ExportFormatConstants.miFormatBMP,axMap1.MapPaperWidth,axMap1.MapScreenHeight);
    //這里有錯誤,不能保存?。。。。。。。。。。?!
    }
    catch(Exception e1)
    {
    MessageBox.Show(e1.Message);
    }

    }

    }
    #endregion


    //*************************


    //*********************************
    #region 編輯菜單按鈕事件,創建編輯地圖工具欄
    //*********************
    private void menuItem27_Click(object sender, System.EventArgs e) //菜單按鈕事件,點擊后,增加可編輯圖層
    {
    if(this.menuItem27.Text.Trim()=="編輯")
    {
    ///******************
    this.menuItem27.Text="取消編輯";
    this.tbadddian.Visible = true;
    this.tbaddxian.Visible = true;
    this.tbaddquxian.Visible = true;
    this.tbaddqumian.Visible = true;
    this.tbline.Visible = true;
    this.tbshezhi.Visible = true;
    ///***************
    ///添加信息,初始化可編輯圖層
    ///
    MapXLib.Layer newLayer;//=new MapXLib.LayerClass();
    MapXLib.LayerInfoClass newLyInfo=new MapXLib.LayerInfoClass();
    MapXLib.FieldsClass newField=new MapXLib.FieldsClass();

    newField.AddStringField("GeoName",10,10);


    newLyInfo.Type=MapXLib.LayerInfoTypeConstants.miLayerInfoTypeTemp;
    newLyInfo.AddParameter("Name","Temporary Layer");
    newLyInfo.AddParameter("Fields",newField);

    newLayer=axMap1.Layers.Add(newLyInfo,1);
    newLayer.Editable=true;
    axMap1.Layers.InsertionLayer=newLayer;


    ///******************************
    ///結束
    ///


    }
    else if(this.menuItem27.Text.Trim()=="取消編輯")
    {
    this.tbadddian.Visible = false;
    this.tbaddxian.Visible = false;
    this.tbaddquxian.Visible = false;
    this.tbaddqumian.Visible = false;
    this.tbline.Visible = false;
    this.tbshezhi.Visible = false;
    this.menuItem27.Text="編輯";


    ///********************
    ///取消那個可編輯圖層
    ///
    axMap1.Layers.Remove(1);


    }

    }
    #endregion


    //*********************************
    #region 可編輯地圖的工具的工具欄


    private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {
    if(e.Button==tbadddian)
    axMap1.CurrentTool=MapXLib.ToolConstants.miAddPointTool; //菜單按鈕事件,在有可編輯地圖的圖層上,添加點,使用“添加點工具”
    if(e.Button==tbaddxian)
    axMap1.CurrentTool=MapXLib.ToolConstants.miAddLineTool; //菜單按鈕事件,在有可編輯地圖的圖層上,添加線,使用“添加線工具”
    if(e.Button==tbaddquxian)
    axMap1.CurrentTool=MapXLib.ToolConstants.miAddPolylineTool; //菜單按鈕事件,在有可編輯地圖的圖層上,添加曲線,使用“添加曲線工具”
    if(e.Button==tbaddqumian)
    axMap1.CurrentTool=MapXLib.ToolConstants.miAddRegionTool; //菜單按鈕事件,在有可編輯地圖的圖層上,添加區域,使用“添加區域工具”
    if(e.Button==tbshezhi)
    {
    Frmeditable frm=new Frmeditable(); //慘淡按鈕事件,是對點、線、區域的樣式進行設置的窗口
    frm.Owner=this;
    frm.ShowDialog();
    }


    }
    #endregion


    //*****************************
    }
    }



    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>