//类
![](/Images/OutliningIndicators/None.gif)
using System;
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
namespace WindowsApplication68
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// DragFeedback 的摘要说明。
/// </summary>
public class DragFeedback
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public DragFeedback()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: 在此处添加构造函数逻辑
//
}
![](/Images/OutliningIndicators/InBlock.gif)
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool Rectangle(IntPtr hdc,int ulCornerX, int ulCornerY,int lrCornerX, int lrCornerY);
[System.Runtime.InteropServices.DllImport("user32.dll") ]
private static extern IntPtr GetDC(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("gdi32.dll") ]
private static extern int SetROP2(IntPtr hdc,int fnDrawMode);
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
public MapObjects2.Rectangle dragfinish(float x,float y)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Rectangle (m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);
![](/Images/OutliningIndicators/InBlock.gif)
r = new MapObjects2.RectangleClass();
![](/Images/OutliningIndicators/InBlock.gif)
// return the rectangle
p = new MapObjects2.PointClass();
p =m_map.ToMapPoint(m_xmin,m_ymin);
r.Left =p.X ;
r.Top =p.Y;
![](/Images/OutliningIndicators/InBlock.gif)
p =m_map.ToMapPoint(m_xmax,m_ymax);
r.Right =p.X ;
r.Bottom =p.Y ;
![](/Images/OutliningIndicators/InBlock.gif)
return r;
}
public void dragmove(float x,float y)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
float xnext;
float ynext;
xnext=x;
ynext=y;
![](/Images/OutliningIndicators/InBlock.gif)
Rectangle(m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);
m_xmin =m_xmin + Convert.ToInt32 (xnext - m_xprev);
m_xmax =m_xmax + Convert.ToInt32 (xnext - m_xprev);
m_ymin =m_ymin + Convert.ToInt32 (ynext - m_yprev);
m_ymax =m_ymax + Convert.ToInt32 (ynext - m_yprev);
![](/Images/OutliningIndicators/InBlock.gif)
Rectangle(m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);
m_xprev =Convert.ToInt32(xnext);
m_yprev =Convert.ToInt32(ynext);
![](/Images/OutliningIndicators/InBlock.gif)
}
public void dragstart(MapObjects2.IMoRectangle rect,AxMapObjects2.AxMap map,float x,float y)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
float xmin,ymin;
float xmax,ymax;
m_map =map;
![](/Images/OutliningIndicators/InBlock.gif)
// initialize the hwnd and hdc variables
m_hwnd =m_map.Handle ;
m_hdc =GetDC(m_map.Handle );
![](/Images/OutliningIndicators/InBlock.gif)
SetROP2(m_hdc,10); // raster op for inverting
![](/Images/OutliningIndicators/InBlock.gif)
p =new MapObjects2.PointClass();
p.X =rect.Left;
p.Y =rect.Top;
![](/Images/OutliningIndicators/InBlock.gif)
xmin=0;
ymin=0;
xmax=0;
ymax=0;
m_map.FromMapPoint(p,ref xmin,ref ymin);
![](/Images/OutliningIndicators/InBlock.gif)
p.X =rect.Right;
p.Y =rect.Bottom;
m_map.FromMapPoint(p,ref xmax,ref ymax);
![](/Images/OutliningIndicators/InBlock.gif)
m_xmin =Convert.ToInt32 (xmin);
m_ymin =Convert.ToInt32 (ymin);
m_xmax =Convert.ToInt32 (xmax);
m_ymax =Convert.ToInt32 (ymax);
![](/Images/OutliningIndicators/InBlock.gif)
// draw the rectangle
Rectangle(m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);
![](/Images/OutliningIndicators/InBlock.gif)
// remember the click position
m_xprev =Convert.ToInt32 (x);
m_yprev =Convert.ToInt32(y);
}
![](/Images/OutliningIndicators/InBlock.gif)
protected MapObjects2.Point p ;
protected AxMapObjects2.AxMap m_map;
protected System.IntPtr m_hdc;
protected System.IntPtr m_hwnd;
protected int m_xmin;
protected int m_ymin;
protected int m_xmax;
protected int m_ymax;
protected int m_xprev;
protected int m_yprev;
public MapObjects2.Rectangle r ;
}
}
![](/Images/OutliningIndicators/None.gif)
//程序主体
![](/Images/OutliningIndicators/None.gif)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
namespace WindowsApplication68
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private AxMapObjects2.AxMap axMap1;
private AxMapObjects2.AxMap axMap2;
private System.Windows.Forms.Button button1;
public DragFeedback DragFeedbk ;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
![](/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)
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
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)
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.axMap1 = new AxMapObjects2.AxMap();
this.axMap2 = new AxMapObjects2.AxMap();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.axMap1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axMap2)).BeginInit();
this.SuspendLayout();
//
// axMap1
//
this.axMap1.Location = new System.Drawing.Point(16, 8);
this.axMap1.Name = "axMap1";
this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState")));
this.axMap1.Size = new System.Drawing.Size(296, 336);
this.axMap1.TabIndex = 0;
this.axMap1.MouseDownEvent += new AxMapObjects2._DMapEvents_MouseDownEventHandler(this.axMap1_MouseDownEvent);
this.axMap1.AfterLayerDraw += new AxMapObjects2._DMapEvents_AfterLayerDrawEventHandler(this.axMap1_AfterLayerDraw);
this.axMap1.MouseUpEvent += new AxMapObjects2._DMapEvents_MouseUpEventHandler(this.axMap1_MouseUpEvent);
//
// axMap2
//
this.axMap2.Location = new System.Drawing.Point(328, 24);
this.axMap2.Name = "axMap2";
this.axMap2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap2.OcxState")));
this.axMap2.Size = new System.Drawing.Size(184, 176);
this.axMap2.TabIndex = 1;
this.axMap2.MouseDownEvent += new AxMapObjects2._DMapEvents_MouseDownEventHandler(this.axMap2_MouseDownEvent);
this.axMap2.AfterTrackingLayerDraw += new AxMapObjects2._DMapEvents_AfterTrackingLayerDrawEventHandler(this.axMap2_AfterTrackingLayerDraw);
this.axMap2.MouseMoveEvent += new AxMapObjects2._DMapEvents_MouseMoveEventHandler(this.axMap2_MouseMoveEvent);
this.axMap2.MouseUpEvent += new AxMapObjects2._DMapEvents_MouseUpEventHandler(this.axMap2_MouseUpEvent);
//
// button1
//
this.button1.Location = new System.Drawing.Point(376, 264);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 32);
this.button1.TabIndex = 2;
this.button1.Text = "full ";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 365);
this.Controls.Add(this.button1);
this.Controls.Add(this.axMap2);
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();
((System.ComponentModel.ISupportInitialize)(this.axMap2)).EndInit();
this.ResumeLayout(false);
![](/Images/OutliningIndicators/InBlock.gif)
}
#endregion
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[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)
{
layer=new MapObjects2.MapLayerClass();
layer.GeoDataset=dc.FindGeoDataset("STATES");
layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moPaleYellow) ;
axMap1.Layers.Add(layer);
![](/Images/OutliningIndicators/InBlock.gif)
layer=new MapObjects2.MapLayerClass();
layer.GeoDataset=dc.FindGeoDataset("ushigh");
layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moDarkGreen) ;
axMap1.Layers.Add(layer);
![](/Images/OutliningIndicators/InBlock.gif)
layer=new MapObjects2.MapLayerClass();
layer.GeoDataset=dc.FindGeoDataset("uslakes");
layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moBlue) ;
axMap1.Layers.Add(layer);
![](/Images/OutliningIndicators/InBlock.gif)
layer=new MapObjects2.MapLayerClass();
layer.GeoDataset=dc.FindGeoDataset("STATES");
layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moPaleYellow) ;
axMap2.Layers.Add(layer);
![](/Images/OutliningIndicators/InBlock.gif)
DragFeedbk =new DragFeedback();
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, System.EventArgs e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
axMap1.Extent=axMap1.FullExtent;
![](/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();
if (e.button==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/InBlock.gif)
r=axMap1.TrackRectangle();
axMap1.Extent=r;
![](/Images/OutliningIndicators/InBlock.gif)
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{ this.Cursor=Cursors.Hand ;
axMap1.Pan();
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap1_AfterLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterLayerDrawEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (e.index ==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
axMap2.TrackingLayer.Refresh(true,0);
}
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap2_AfterTrackingLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterTrackingLayerDrawEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapObjects2.Symbol sym;
sym=new MapObjects2.SymbolClass();
sym.OutlineColor=Convert.ToUInt32 (MapObjects2.ColorConstants.moRed);
sym.Style =1 ;
axMap2.DrawShape(axMap1.Extent,sym);
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap2_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MapObjects2.Point p;
p=new MapObjects2.PointClass();
p=axMap2.ToMapPoint(e.x,e.y );
if (axMap1.Extent.IsPointIn(p))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DragFeedbk .dragstart(axMap1.Extent ,axMap2,e.x,e.y );
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap2_MouseMoveEvent(object sender, AxMapObjects2._DMapEvents_MouseMoveEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (e.button==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
DragFeedbk.dragmove(e.x,e.y );
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap1_MouseUpEvent(object sender, AxMapObjects2._DMapEvents_MouseUpEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
private void axMap2_MouseUpEvent(object sender, AxMapObjects2._DMapEvents_MouseUpEvent e)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
axMap2.CtlRefresh();
axMap1.Extent=DragFeedbk.dragfinish(e.x,e.y );
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)