mo+c#中的 tips 实现
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
![](/Images/OutliningIndicators/None.gif)
namespace WindowsApplication67
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private AxMapObjects2.AxMap axMap1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
public maptips2 tips;
![](/Images/OutliningIndicators/InBlock.gif)
public Form1()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
![](/Images/OutliningIndicators/InBlock.gif)
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( disposing )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (components != null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.axMap1 = new AxMapObjects2.AxMap();
this.textBox1 = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.axMap1)).BeginInit();
this.SuspendLayout();
//
// axMap1
//
this.axMap1.Location = new System.Drawing.Point(16, 24);
this.axMap1.Name = "axMap1";
this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState")));
this.axMap1.Size = new System.Drawing.Size(392, 224);
this.axMap1.TabIndex = 0;
this.axMap1.MouseDownEvent += new AxMapObjects2._DMapEvents_MouseDownEventHandler(this.axMap1_MouseDownEvent);
this.axMap1.MouseMoveEvent += new AxMapObjects2._DMapEvents_MouseMoveEventHandler(this.axMap1_MouseMoveEvent);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(168, 64);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(80, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(496, 285);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.axMap1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.axMap1)).EndInit();
this.ResumeLayout(false);
![](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Application.Run(new Form1());
}
![](/Images/OutliningIndicators/InBlock.gif)
private void Form1_Load(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapObjects2.IMoDataConnection dc;
MapObjects2.IMoMapLayer layer;
dc=new MapObjects2.DataConnectionClass();
dc.Database=@"f:\data\usa";
if (!dc.Connect())
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show("无法连");
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
layer=new MapObjects2.MapLayerClass();
layer.GeoDataset=dc.FindGeoDataset("STATES");
axMap1.Layers.Add(layer);
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
tips=new maptips2();
tips.initialize(axMap1,timer1,textBox1);
tips.setlay(layer,"STATE_NAME");
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap1_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapObjects2.Rectangle r;
r= new MapObjects2.RectangleClass();
r=axMap1.TrackRectangle() ;
![](/Images/OutliningIndicators/InBlock.gif)
axMap1.Extent=r;
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap1_MouseMoveEvent(object sender, AxMapObjects2._DMapEvents_MouseMoveEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.tips.mousemove(e.x,e.y );
}
![](/Images/OutliningIndicators/InBlock.gif)
private void timer1_Tick(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.tips.timer();
}
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
//类
![](/Images/OutliningIndicators/None.gif)
using System;
using MapObjects2;
![](/Images/OutliningIndicators/None.gif)
namespace WindowsApplication67
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////
/// maptips2 的摘要说明。
///
public class maptips2
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public maptips2()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: 在此处添加构造函数逻辑
//
}
protected int m_x;
protected int m_y;
protected int m_lastx;
protected int m_lasty;
protected AxMapObjects2.AxMap axMap1;
protected System.Windows.Forms.Timer m_time;
protected System.Windows.Forms.TextBox m_edit;
protected MapObjects2.IMoMapLayer m_layer;
protected string m_field;
protected MapObjects2.Recordset m_recs;
![](/Images/OutliningIndicators/InBlock.gif)
public void doseach()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapObjects2.Point pt;
pt=new MapObjects2.PointClass();
pt=axMap1.ToMapPoint(m_x,m_y);
if (m_layer.shapeType.ToString()=="23")
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_recs=m_layer.SearchShape(pt,MapObjects2.SearchMethodConstants.moPointInPolygon ,"");
![](/Images/OutliningIndicators/InBlock.gif)
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_recs=m_layer.SearchByDistance(pt,axMap1.ToMapDistance(10),"");
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
}
public void initialize(AxMapObjects2.AxMap map,System.Windows.Forms.Timer tmr,System.Windows.Forms.TextBox edit )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
axMap1=map;
m_time=tmr;
m_edit=edit;
m_edit.Visible=false;
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
public void mousemove(int x,int y)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if ( m_time.Interval==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_x=x;
m_y=y;
m_time.Interval=100;
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_edit.Visible=false;
![](/Images/OutliningIndicators/InBlock.gif)
}
}
public void setlay(MapObjects2.IMoMapLayer layer,string fid)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_layer=layer;
m_field=fid;
![](/Images/OutliningIndicators/InBlock.gif)
}
public void showtiptext(string text)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_edit.Text=text;
m_edit.Visible=true;
m_edit.Left=axMap1.Left+m_x;
m_edit.Top =axMap1.Top+m_y+20;
![](/Images/OutliningIndicators/InBlock.gif)
}
public void timer()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string s;
MapObjects2.IMoFields flds;
MapObjects2.IMoField fld ;
if ((m_x==m_lastx)&&(m_y==m_lasty))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_time.Interval=1;
doseach();
if(m_recs.EOF )
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_edit.Visible=false;
![](/Images/OutliningIndicators/InBlock.gif)
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flds=m_recs.Fields ;
fld= flds.Item(m_field);
s=fld.Value.ToString();
this.showtiptext(s);
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_lastx=m_x;
m_lasty=m_y;
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
原文地址:https://www.cnblogs.com/gwazy/p/111131.html