ITeye博客

MapxTreme2005地图打印

seven7680 · 2009-03-30 16:18 · MapXtreme · Markdown

MapxTreme2005地图打印 一、语言: c# net2003 二、组件:Mapxtreme2005 三、功能概述: 初步实现地图的加载,页面设置,打印预览及打印功能

五、实现思路与过程: (当然在做这个程序的时候, Mapxtreme2005程序是必须安装的)

  1. 启动 Microsoft Visual Studio .NET 2003,新建工程,在项目类型中选择MapXtreme6.5项目下的c#项目(当然,你可创建基于vb的工程,但该程序是建立在c# 项目上的),然后在模板中选择,当然你可创建其他的应用程序,如windows应用程序等,然后设置工程名,我这里设工程名为:PrintingDemo,当然你可设置自己喜爱的工程名;到这里一个具有GIS基本功能的程序已设置完成,运行一下,是不是在MapX中花很大力气完成的功能,在这里并不需写一个字母,这就是模板的效果,让你快速搭建自己的应用程序。 2.开始编写自己想要的功能程序,在这里首先我们添加一个,然后添加菜单,并在下面设置如下四个下拉菜单:

加载地图:mItAddmap,

页面设置:mItPageSetting,

打印预览:mItPrintPreview,

打印: mItPrintting。 并处理他们的单击事件。

3.为了实现打印功能,添加引用 ,然后再添加using 指令:

using MapInfo.Mapping; using System.Drawing.Printing; using MapInfo.Printing ; using MapInfo.Mapping.Thematics; using MapInfo.Engine;using MapInfo.Windows.Dialogs; 4.实现相关单击功能: 添加三个变量: private System.Windows.Forms.OpenFileDialog openFileDialog1; private MapInfo.Printing.MapPrinting mapPrinting; private MapInfo.Printing.MapPrintDocument mapPrintDocument; this.mapPrinting=new MapPrinting(); this.mapPrintDocument=new MapPrintDocument(); this.mapPrinting=new MapPrinting(); this.openFileDialog1=new System.Windows.Forms.OpenFileDialog(); 加载地图的代码如下: private void mItAddmap_Click(object sender, System.EventArgs e) { //进行文件的路径设置 openFileDialog1.InitialDirectory = Session.Current.TableSearchPath.Path; //打开文件格式的自定义 openFileDialog1.Multiselect = true; openFileDialog1.CheckFileExists = true; openFileDialog1.DefaultExt = "TAB"; openFileDialog1.Filter = "MapInfo Tables (.tab)|.tab|" +"MapInfo Geoset (.gst)|.gst|" +"MapInfo WorkSpace (.mws)|.mws"; string strCantOpenList = null; //判断不同类型的文档进行加载 if(openFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) foreach(string filename in openFileDialog1.FileNames) try { if (filename.ToLower().EndsWith(MapLoader.FileExtensionGST)) mapControl1.Map.Load(new MapGeosetLoader(filename)); // add geoset else if (filename.ToLower().EndsWith(MapLoader.FileExtensionWOR)) { mapControl1.Map.Load(new MapWorkSpaceLoader(filename)); // add workspace mapControl1.Map.Size = mapControl1.Size; } else mapControl1.Map.Load(new MapTableLoader(filename)); // add table } //若没找到正确的文件格式,则进行异常抛出 catch(MapException me) { if (strCantOpenList==null) strCantOpenList = me.Arg; else strCantOpenList = strCantOpenList + ", " + me.Arg; } } 页面设置的代码如下: private void mItPageSetting_Click(object sender, System.EventArgs e) { //加载当前地图 mapPrinting.Map = mapControl1.Map ; //启动页面设置 mapPrinting.PageSettingsDialog (); mapPrinting.PageSettings.PrinterSettings.PrinterResolutions.ToString(); } 打印预览的代码如下: private void mItPrintPreview_Click(object sender, System.EventArgs e) { //加载当前地图 mapPrinting.Map = mapControl1.Map ; //启动打印预览 mapPrinting.PrintPreview(); LegendPrinting legendPrinting=new LegendPrinting();

} 打印的代码如下: private void mItPrintting_Click(object sender, System.EventArgs e) { //加载当前地图 mapPrinting.Map =mapControl1.Map ; //加载打印对话框 mapPrinting.ShowDialog =true; mapPrinting.Print(); if (mapPrintDocument != null) { //设置打印地图的基本属性 mapPrintDocument.DrawingAttributes.SpecialTransparentRasterHandling =false; bmapPrintDocument.PrintMethod = PrintMethod.Direct; } } 5.说明,由于是初学,打印代码没有涉及更深层次的,比如在打印时用户可进行自行定义等。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。