C#+MO实现一些渲染功能

2016-02-19 11:12 27 1 收藏

今天图老师小编要跟大家分享C#+MO实现一些渲染功能,精心挑选的过程简单易学,喜欢的朋友一起来学习吧!

【 tulaoshi.com - 编程语言 】

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DbInMo
{
     /// summary
     /// Form1 的摘要说明。
     /// /summary
     public class 渲染示例 : System.Windows.Forms.Form
     {
          private AxMapObjects2.AxMap map;
          private System.Windows.Forms.Button 直方图;
          private System.Windows.Forms.Button 饼图;
          private System.Windows.Forms.Button 点密度;
          private System.Windows.Forms.Button 按值渲染;
          private System.Windows.Forms.Button 分类渲染;
          private System.Windows.Forms.Button Z值渲染;
          private System.Windows.Forms.Button 组渲染;
          private System.Windows.Forms.Button 退出;
          private System.Windows.Forms.Panel 操作板;
          private System.Windows.Forms.Button 删除所有渲染;
          private System.Windows.Forms.Panel panel1;
          private System.Windows.Forms.Button 全图;
          private System.Windows.Forms.Button 拖动;
          private System.Windows.Forms.Button 缩小;
          private System.Windows.Forms.Button 放大;
          private System.Windows.Forms.Panel 分隔符;
          private System.Windows.Forms.Button 标注渲染;
         /// summary
         /// 必需的设计器变量。
         /// /summary
          private System.ComponentModel.Container components = null;
         public 渲染示例()
         {
              //
              // Windows 窗体设计器支持所必需的
              //
              InitializeComponent();
              //
              // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
              //
         }
         /// 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 resources = new System.Resources.ResourceManager(typeof(渲染示例));
              this.map = new AxMapObjects2.AxMap();
              this.操作板 = new System.Windows.Forms.Panel();
              this.直方图 = new System.Windows.Forms.Button();
              this.饼图 = new System.Windows.Forms.Button();
              this.点密度 = new System.Windows.Forms.Button();
              this.按值渲染 = new System.Windows.Forms.Button();
              this.分类渲染 = new System.Windows.Forms.Button();
              this.Z值渲染 = new System.Windows.Forms.Button();
              this.组渲染 = new System.Windows.Forms.Button();
              this.退出 = new System.Windows.Forms.Button();
              this.标注渲染 = new System.Windows.Forms.Button();
              this.删除所有渲染 = new System.Windows.Forms.Button();
              this.panel1 = new System.Windows.Forms.Panel();
              this.全图 = new System.Windows.Forms.Button();
              this.拖动 = new System.Windows.Forms.Button();
              this.缩小 = new System.Windows.Forms.Button();
              this.放大 = new System.Windows.Forms.Button();
              this.分隔符 = new System.Windows.Forms.Panel();
              ((System.ComponentModel.ISupportInitialize)(this.map)).BeginInit();
              this.操作板.SuspendLayout();
              this.SuspendLayout();
              // 
              // map
              // 
              this.map.Dock = System.Windows.Forms.DockStyle.Fill;
              this.map.Location = new System.Drawing.Point(0, 0);
              this.map.Name = "map";
              this.map.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("map.OcxState")));
              this.map.Size = new System.Drawing.Size(616, 429);
              this.map.TabIndex = 0;
              this.map.MouseDownEvent += new AxMapObjects2._DMapEvents_MouseDownEventHandler(this.map_MouseDownEvent);
              // 
              // 操作板
              // 
              this.操作板.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
              this.操作板.Controls.Add(this.删除所有渲染);
              this.操作板.Controls.Add(this.panel1);
              this.操作板.Controls.Add(this.全图);
              this.操作板.Controls.Add(this.拖动);
              this.操作板.Controls.Add(this.缩小);
              this.操作板.Controls.Add(this.放大);
              this.操作板.Controls.Add(this.分隔符);
              this.操作板.Controls.Add(this.标注渲染);
              this.操作板.Controls.Add(this.退出);
              this.操作板.Controls.Add(this.组渲染);
              this.操作板.Controls.Add(this.Z值渲染);
              this.操作板.Controls.Add(this.分类渲染);
              this.操作板.Controls.Add(this.按值渲染);
              this.操作板.Controls.Add(this.点密度);
              this.操作板.Controls.Add(this.饼图);
              this.操作板.Controls.Add(this.直方图);
              this.操作板.Dock = System.Windows.Forms.DockStyle.Right;
              this.操作板.Location = new System.Drawing.Point(496, 0);
              this.操作板.Name = "操作板";
              this.操作板.Size = new System.Drawing.Size(120, 429);
              this.操作板.TabIndex = 1;
              // 
              // 直方图
              // 
              this.直方图.Dock = System.Windows.Forms.DockStyle.Top;
              this.直方图.Location = new System.Drawing.Point(0, 0);
              this.直方图.Name = "直方图";
              this.直方图.Size = new System.Drawing.Size(116, 24);
              this.直方图.TabIndex = 0;
              this.直方图.Text = "直方图";
              this.直方图.Click += new System.EventHandler(this.直方图_Click);
              // 
              // 饼图
              // 
              this.饼图.Dock = System.Windows.Forms.DockStyle.Top;
              this.饼图.Location = new System.Drawing.Point(0, 24);
              this.饼图.Name = "饼图";
              this.饼图.Size = new System.Drawing.Size(116, 24);
              this.饼图.TabIndex = 1;
              this.饼图.Text = "饼图";
              this.饼图.Click += new System.EventHandler(this.饼图_Click);
              // 
              // 点密度
              // 
              this.点密度.Dock = System.Windows.Forms.DockStyle.Top;
              this.点密度.Location = new System.Drawing.Point(0, 48);
              this.点密度.Name = "点密度";
              this.点密度.Size = new System.Drawing.Size(116, 23);
              this.点密度.TabIndex = 2;
              this.点密度.Text = "点密度";
              this.点密度.Click += new System.EventHandler(this.点密度_Click);
              // 
              // 按值渲染
              // 
              this.按值渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.按值渲染.Location = new System.Drawing.Point(0, 71);
              this.按值渲染.Name = "按值渲染";
              this.按值渲染.Size = new System.Drawing.Size(116, 23);
              this.按值渲染.TabIndex = 3;
              this.按值渲染.Text = "按值渲染";
              this.按值渲染.Click += new System.EventHandler(this.按值渲染_Click);
              // 
              // 分类渲染
              // 
              this.分类渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.分类渲染.Location = new System.Drawing.Point(0, 94);
              this.分类渲染.Name = "分类渲染";
              this.分类渲染.Size = new System.Drawing.Size(116, 23);
              this.分类渲染.TabIndex = 4;
              this.分类渲染.Text = "分类渲染";
              this.分类渲染.Click += new System.EventHandler(this.分类渲染_Click);
              // 
              // Z值渲染
              // 
              this.Z值渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.Z值渲染.Location = new System.Drawing.Point(0, 117);
              this.Z值渲染.Name = "Z值渲染";
              this.Z值渲染.Size = new System.Drawing.Size(116, 23);
              this.Z值渲染.TabIndex = 5;
              this.Z值渲染.Text = "Z值渲染";
              this.Z值渲染.Click += new System.EventHandler(this.Z值渲染_Click);
              // 
              // 组渲染
              // 
              this.组渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.组渲染.Location = new System.Drawing.Point(0, 140);
              this.组渲染.Name = "组渲染";
              this.组渲染.Size = new System.Drawing.Size(116, 23);
              this.组渲染.TabIndex = 6;
              this.组渲染.Text = "组渲染";
              this.组渲染.Click += new System.EventHandler(this.组渲染_Click);
              // 
              // 退出
              // 
              this.退出.Dock = System.Windows.Forms.DockStyle.Bottom;
              this.退出.Location = new System.Drawing.Point(0, 402);
              this.退出.Name = "退出";
              this.退出.Size = new System.Drawing.Size(116, 23);
              this.退出.TabIndex = 7;
              this.退出.Text = "退出";
              this.退出.Click += new System.EventHandler(this.退出_Click);
              // 
              // 标注渲染
              // 
              this.标注渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.标注渲染.Location = new System.Drawing.Point(0, 163);
              this.标注渲染.Name = "标注渲染";
              this.标注渲染.Size = new System.Drawing.Size(116, 23);
              this.标注渲染.TabIndex = 7;
              this.标注渲染.Text = "标注渲染";
              this.标注渲染.Click += new System.EventHandler(this.标注渲染_Click);
              // 
              // 删除所有渲染
              // 
              this.删除所有渲染.Dock = System.Windows.Forms.DockStyle.Top;
              this.删除所有渲染.Location = new System.Drawing.Point(0, 319);
              this.删除所有渲染.Name = "删除所有渲染";
              this.删除所有渲染.Size = new System.Drawing.Size(116, 23);
              this.删除所有渲染.TabIndex = 22;
              this.删除所有渲染.Text = "删除所有渲染";
              this.删除所有渲染.Click += new System.EventHandler(this.删除所有渲染_Click);
              // 
              // panel1
              // 
              this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
              this.panel1.Location = new System.Drawing.Point(0, 299);
              this.panel1.Name = "panel1";
              this.panel1.Size = new System.Drawing.Size(116, 20);
              this.panel1.TabIndex = 21;
              // 
              // 全图
              // 
              this.全图.Dock = System.Windows.Forms.DockStyle.Top;
              this.全图.Location = new System.Drawing.Point(0, 276);
              this.全图.Name = "全图";
              this.全图.Size = new System.Drawing.Size(116, 23);
              this.全图.TabIndex = 20;
              this.全图.Text = "全图";
              this.全图.Click += new System.EventHandler(this.全图_Click);
              // 
              // 拖动
              // 
              this.拖动.Dock = System.Windows.Forms.DockStyle.Top;
              this.拖动.Location = new System.Drawing.Point(0, 253);
              this.拖动.Name = "拖动";
              this.拖动.Size = new System.Drawing.Size(116, 23);
              this.拖动.TabIndex = 19;
              this.拖动.Text = "拖动";
              this.拖动.Click += new System.EventHandler(this.拖动_Click);
              // 
              // 缩小
              // 
              this.缩小.Dock = System.Windows.Forms.DockStyle.Top;
              this.缩小.Location = new System.Drawing.Point(0, 230);
              this.缩小.Name = "缩小";
              this.缩小.Size = new System.Drawing.Size(116, 23);
              this.缩小.TabIndex = 18;
              this.缩小.Text = "缩小";
              this.缩小.Click += new System.EventHandler(this.缩小_Click);
              // 
              // 放大
              // 
              this.放大.Dock = System.Windows.Forms.DockStyle.Top;
              this.放大.Location = new System.Drawing.Point(0, 207);
              this.放大.Name = "放大";
              this.放大.Size = new System.Drawing.Size(116, 23);
              this.放大.TabIndex = 17;
              this.放大.Text = "放大";
              this.放大.Click += new System.EventHandler(this.放大_Click);
              // 
              // 分隔符
              // 
              this.分隔符.Dock = System.Windows.Forms.DockStyle.Top;
              this.分隔符.Location = new System.Drawing.Point(0, 186);
              this.分隔符.Name = "分隔符";
              this.分隔符.Size = new System.Drawing.Size(116, 21);
              this.分隔符.TabIndex = 16;
              // 
              // 渲染示例
              // 
              this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
              this.ClientSize = new System.Drawing.Size(616, 429);
              this.Controls.Add(this.操作板);
              this.Controls.Add(this.map);
              this.Name = "渲染示例";
              this.Text = "渲染示例";
              this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
              ((System.ComponentModel.ISupportInitialize)(this.map)).EndInit();
              this.操作板.ResumeLayout(false);
              this.ResumeLayout(false);
         }
          #endregion
         /// summary
         /// 应用程序的主入口点。
         /// /summary
          [STAThread]
         static void Main() 
         {
              Application.Run(new 渲染示例());
         }
         /// summary
         /// 退出系统
         /// /summary
          private void 退出_Click(object sender, System.EventArgs e)
         {
              this.Close();
         }
         /// summary
         /// 图表渲染,值方图
         /// /summary
          private void 直方图_Click(object sender, System.EventArgs e)
         {
              //直方图的例子中使用Lakers图层
              //
              //定义图标渲染变量
              MapObjects2.ChartRenderer cr = new MapObjects2.ChartRendererClass();
              //设置渲染类型为直方图
              cr.ChartType = MapObjects2.ChartTypeConstants.moBar;
              //设置直方图显示的字段个数为两个,就是直方图显示两个柱子
              cr.FieldCount = 2;
              //设置第一个字段,请参看lakes.dbf
              cr.set_Field(0,"SURF_ELEV");
              //设置这个直方图的柱子颜色为红色
              cr.set_Color(0,(uint)MapObjects2.ColorConstants.moRed);
              //设置第二个柱子
              cr.set_Field(1,"DEPTH");
              cr.set_Color(1,(uint)MapObjects2.ColorConstants.moGreen);
              MapObjects2.MapLayer lyr = (MapObjects2.MapLayer)(map.Layers.Item("lakes"));
              lyr.Renderer = cr;
              //使用Refresh()刷新老也是刷新不好,正没办法。。。,设为全图倒是不错的注意,^_^
              map.Refresh();
         }
         /// summary
         /// 全图视野
         /// /summary
          private void 全图_Click(object sender, System.EventArgs e)
         {
              map.Extent = map.FullExtent;
         }
         /// summary
         /// 拖动,只设置图标
         /// /summary
          private void 拖动_Click(object sender, System.EventArgs e)
         {
              map.MousePointer = MapObjects2.MousePointerConstants.moPan;
         }
         /// summary
         /// 缩小,只设置图标
         /// /summary
          private void 缩小_Click(object sender, System.EventArgs e)
         {
              map.MousePointer = MapObjects2.MousePointerConstants.moZoomOut;
         }
         /// summary
         /// 放大,只设置图标
         /// /summary
          private void 放大_Click(object sender, System.EventArgs e)
         {
              map.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;
         }
         /// summary
         /// 鼠标按下时间,处理地图放大、缩小、拖动等。
         /// /summary
          private void map_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)
         {
              MapObjects2.Rectangle rect;
              MapObjects2.Point pt = map.ToMapPoint(e.x,e.y);
              if(e.button == 2)//右键点击取消
              {
                   map.MousePointer = MapObjects2.MousePointerConstants.moDefault;
              }
              if(map.MousePointer == MapObjects2.MousePointerConstants.moPan)//拖动
              {
                   map.Pan();
              }
              else if(map.MousePointer == MapObjects2.MousePointerConstants.moZoomIn)//放大
              {
                   rect = map.TrackRectangle();
                   if(rect == null|| (rect.Width  0.00005) || (rect.Height  0.00005))
                   {                           
                       rect = map.Extent;
                        rect.ScaleRectangle(0.6667);
                        rect.Offset(-(rect.Center.X - pt.X),-(rect.Center.Y - pt.Y));
                   }
                   map.Extent = rect;
              }
              else if(map.MousePointer == MapObjects2.MousePointerConstants.moZoomOut)//缩小
              {
                   rect = map.TrackRectangle();
                   if ((null == rect) || (rect.Width  0.00005) || (rect.Height  0.00005))
                   {
                       rect = map.Extent;
                        rect.ScaleRectangle(1.5);
                        rect.Offset(-(rect.Center.X - pt.X),-(rect.Center.Y - pt.Y));
                   }
                   else
                   {    
                       double dRate = map.Extent.Width / rect.Width * 10;  
                        rect.ScaleRectangle(dRate);
                   }
                   map.Extent = rect;
              }
          }
         /// summary
         /// 图表渲染,使用饼图
         /// /summary
          private void 饼图_Click(object sender, System.EventArgs e)
         {
              //饼图的例子中使用Lakers图层
              //过程和直方图一样
              //
              //定义图标渲染变量
              MapObjects2.ChartRenderer cr = new MapObjects2.ChartRendererClass();
              //设置渲染类型为饼图
              cr.ChartType = MapObjects2.ChartTypeConstants.moPie;
              //设置饼图显示的字段个数为两个,就是饼图显示两半
              cr.FieldCount = 2;
              //设置第一个字段,请参看lakes.dbf
              cr.set_Field(0,"SURF_ELEV");
              //设置这个饼图的一半颜色为红色
              cr.set_Color(0,(uint)MapObjects2.ColorConstants.moRed);
              //设置第二半
              cr.set_Field(1,"DEPTH");
              cr.set_Color(1,(uint)MapObjects2.ColorConstants.moGreen);
              //添加到地图上
              MapObjects2.MapLayer lyr = (MapObjects2.MapLayer)(map.Layers.Item("lakes"));
              lyr.Renderer = cr;
              //刷新
              map.Refresh();      
         }
         /// summary
         /// 点密度渲染
         /// /summary
          private void 点密度_Click(object sender, System.EventArgs e)
         {
              //点密度的例子中使用lakes图层
              //
              //定义点密度渲染变量
              MapObjects2.DotDensityRenderer ddr = new MapObjects2.DotDensityRendererClass();
              //设置渲染的数据字段,请参看lakes.dbf
              ddr.Field = "DEPTH";
              //点大小
              ddr.DotSize = 3;
              //点颜色
              ddr.DotColor = (uint)MapObjects2.ColorConstants.moBlue;
              ddr.DotValue = 1;
              ddr.DrawBackground = true;
              //添加到地图上
              MapObjects2.MapLayer lyr = (MapObjects2.MapLayer)(map.Layers.Item("lakes"));
              lyr.Renderer = ddr;
              //刷新
              map.Refresh();
         }
         /// summary
         /// 按值渲染
         /// /summary
          private void 按值渲染_Click(object sender, System.EventArgs e)
         {
              //按值渲染的例子中使用country图层,这里利用按值渲染,将每个国家用不同的颜色显示
              //
              //字符串s变量,很像Delphi中的TStringList,^_^
              MapObjects2.Strings strs = new MapObjects2.StringsClass();
              //图层变量,引用country图层
              MapObjects2.MapLayer lyr = (MapObjects2.MapLayer)map.Layers.Item("country");
              //Recordset对象,我将在以后的文章中陆续讲解关于MapObjects2.2中使用数据集变量的内容!!!
              //使用方法大致与VB中对数据表的操作差不多。
              MapObjects2.Recordset rc = lyr.Records;
              //这个循环获取所有国家的简称代码列表
              while(!rc.EOF)
              {
                   strs.Add(rc.Fields.Item("FIPS_CODE").ValueAsString);
                   rc.MoveNext();
              }
              //定义按值渲染对象
              MapObjects2.ValueMapRenderer vmr = new MapObjects2.ValueMapRendererClass();
              //将其添加到图层
              lyr.Renderer = vmr;
              //设置渲染使用的字段,请参看country.dbf文件
              vmr.Field = "FIPS_CODE";
              //渲染的个数
              vmr.ValueCount = strs.Count;
              //缺省值
              vmr.UseDefault = true;
              MapObjects2.Symbol sym = vmr.DefaultSymbol;
              sym.Color = (uint)MapObjects2.ColorConstants.moYellow;//缺省颜色为黄色
              //渲染过程
              for(int i=0;ivmr.ValueCount;i++)
              {
                   vmr.set_Value((short)i,strs.Item((short)i));
              }
              //刷新
              map.Refresh();
         }
         /// summary
         /// 分类渲染
         /// /summary
          private void 分类渲染_Click(object sender, System.EventArgs e)
         {
              //分类渲染的例子使用country图层
              //
              //图层变量引用cities层
              MapObjects2.MapLayer lyr = (MapObjects2.MapLayer)(map.Layers.Item("cities"));
              //定义分类渲染变量
              MapObjects2.ClassBreaksRenderer cbr = new MapObjects2.ClassBreaksRendererClass();
              //添加到地图
              lyr.Renderer = cbr;
              //设置符号类型为点,也可使用其他类型,请自己试验,方法大概都差不多
              cbr.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol;
              //设置字段,请参看cities.dbf文件
              cbr.Field = "POPULATION";
              //Statistics对象经常配合分类渲染使用,他表示用一个Recordset对象的CalculateStatistics方法
              //  对一个数值字段的统计计算结果
              MapObjects2.Statistics stat = lyr.Records.CalculateStatistics("POPULATION");
              //Mean——平均值,StdDev——均方差
              double fbv = stat.Mean - (stat.StdDev * 3);
              for(int i=0;i6;i++)
              {

来源:http://www.tulaoshi.com/n/20160219/1596743.html

延伸阅读
标签: 电脑入门
①我们先来说标尺吧,做为文档编辑的好帮手,标尺必不可少,我们单击下图红色方框标记的按钮,就能显示标尺了。 ②标尺显示出来了,我们双击标尺下方的空白处,可以快速的隐藏这些空白。 ③接下来我们要说的就是制表位了,如下图,点击红色方框标记的地方,即可选择制表位。
标签: Web开发
总结出关于W3C CSS标准的一些经验: 一、少用偏门。类似break-word断行,z-index手动分层,还有像垂直对齐等等这些偏门CSS最好少用,因为不一定所有浏览器都支持,而且极难通过W3C检测。 二、center不是float的值。很多新手都会把center误认为是float的值,而偏偏不是如此。center只是text-align的值。 三、对齐不能包...
最近用C#写了一个vs的插件,主要功能是插入标准的注释段和一些常用的代码段。在开发过程中,遇到了一些问题,也翻阅了一些资料,做了一番研究。这里对其中的一些小问题做一个简单的纪录,希望能够有所帮助。 (1)在OnConnection中,判断connectMode时,一定要加上ext_cm_AfterStartup    if(connectMode == Extensibility.ext_Con...
标签: 包装
谢谢大家的支持和鼓励,再分享一些在包装效果图做工艺效果的小经验,有部分是吸取了网上的经验,感谢原作者!
标签: 生活常识
一些冷冷冷知识   右撇子的寿命比左撇子平均长九年。 肝脏有五百种以上的功能。 如果把人类的DNA 展开来,长度可以来回月球三千次。 一边的眉毛大约有550 根。 人体的重量大约是大脑的40 倍以上。 人类大脑大约三磅(约1400 克) 重,但两磅(约900 克) 以上是水。 ...