阅读:2359回复:5
mo+c#中鹰眼的实现
<H2> </H2>
<P>//类</P> <P>using System;</P> <P>namespace WindowsApplication68 { /// <summary> /// DragFeedback 的摘要说明。 /// </summary> public class DragFeedback { public DragFeedback() { // // TOD 在此处添加构造函数逻辑 // }</P> <P> [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);</P> <P> public MapObjects2.Rectangle dragfinish(float x,float y) { Rectangle (m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);</P> <P> r = new MapObjects2.RectangleClass();</P> <P> // return the rectangle p = new MapObjects2.PointClass(); p =m_map.ToMapPoint(m_xmin,m_ymin); r.Left =p.X ; r.Top =p.Y;</P> <P> p =m_map.ToMapPoint(m_xmax,m_ymax); r.Right =p.X ; r.Bottom =p.Y ;</P> <P> return r; } public void dragmove(float x,float y) { float xnext; float ynext; xnext=x; ynext=y;</P> <P> 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);</P> <P> Rectangle(m_hdc,m_xmin,m_ymin,m_xmax,m_ymax); m_xprev =Convert.ToInt32(xnext); m_yprev =Convert.ToInt32(ynext);</P> <P> } public void dragstart(MapObjects2.IMoRectangle rect,AxMapObjects2.AxMap map,float x,float y) { float xmin,ymin; float xmax,ymax; m_map =map;</P> <P> // initialize the hwnd and hdc variables m_hwnd =m_map.Handle ; m_hdc =GetDC(m_map.Handle ); </P> <P> SetROP2(m_hdc,10); // raster op for inverting</P> <P> p =new MapObjects2.PointClass(); p.X =rect.Left; p.Y =rect.Top;</P> <P> xmin=0; ymin=0; xmax=0; ymax=0; m_map.FromMapPoint(p,ref xmin,ref ymin);</P> <P> p.X =rect.Right; p.Y =rect.Bottom; m_map.FromMapPoint(p,ref xmax,ref ymax);</P> <P> m_xmin =Convert.ToInt32 (xmin); m_ymin =Convert.ToInt32 (ymin); m_xmax =Convert.ToInt32 (xmax); m_ymax =Convert.ToInt32 (ymax);</P> <P> // draw the rectangle Rectangle(m_hdc,m_xmin,m_ymin,m_xmax,m_ymax);</P> <P> // remember the click position m_xprev =Convert.ToInt32 (x); m_yprev =Convert.ToInt32(y); }</P> <P> 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 ; } }</P> <P>//程序主体</P> <P>using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;</P> <P> namespace WindowsApplication68 { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private AxMapObjects2.AxMap axMap1; private AxMapObjects2.AxMap axMap2; private System.Windows.Forms.Button button1; public DragFeedback DragFeedbk ; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null;</P> <P> public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent();</P> <P> // // TOD 在 InitializeComponent 调用后添加任何构造函数代码 // }</P> <P> /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }</P> <P> #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { 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);</P> <P> } #endregion</P> <P> /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }</P> <P> private void Form1_Load(object sender, System.EventArgs e) { MapObjects2.IMoDataConnection dc; MapObjects2.IMoMapLayer layer; dc=new MapObjects2.DataConnectionClass(); <a href='mailtdc.Database=@"f:\data\usa' target="_blank" >dc.Database=@"f:\data\usa</A>"; if (dc.Connect() ) { layer=new MapObjects2.MapLayerClass(); layer.GeoDataset=dc.FindGeoDataset("STATES"); layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moPaleYellow) ; axMap1.Layers.Add(layer);</P> <P> layer=new MapObjects2.MapLayerClass(); layer.GeoDataset=dc.FindGeoDataset("ushigh"); layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moDarkGreen) ; axMap1.Layers.Add(layer);</P> <P> layer=new MapObjects2.MapLayerClass(); layer.GeoDataset=dc.FindGeoDataset("uslakes"); layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moBlue) ; axMap1.Layers.Add(layer);</P> <P> layer=new MapObjects2.MapLayerClass(); layer.GeoDataset=dc.FindGeoDataset("STATES"); layer.Symbol.Color=Convert.ToUInt32(MapObjects2.ColorConstants.moPaleYellow) ; axMap2.Layers.Add(layer);</P> <P> DragFeedbk =new DragFeedback(); }</P> <P> }</P> <P> </P> <P> private void button1_Click(object sender, System.EventArgs e) { axMap1.Extent=axMap1.FullExtent; </P> <P> }</P> <P> private void axMap1_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e) { MapObjects2.Rectangle r; r=new MapObjects2.RectangleClass(); if (e.button==1) { </P> <P> r=axMap1.TrackRectangle(); axMap1.Extent=r; </P> <P> } else { this.Cursor=Cursors.Hand ; axMap1.Pan();</P> <P> }</P> <P> }</P> <P> private void axMap1_AfterLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterLayerDrawEvent e) { if (e.index ==0) { axMap2.TrackingLayer.Refresh(true,0); } }</P> <P> private void axMap2_AfterTrackingLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterTrackingLayerDrawEvent e) { MapObjects2.Symbol sym; sym=new MapObjects2.SymbolClass(); sym.OutlineColor=Convert.ToUInt32 (MapObjects2.ColorConstants.moRed); sym.Style =1 ; axMap2.DrawShape(axMap1.Extent,sym);</P> <P> }</P> <P> private void axMap2_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e) { MapObjects2.Point p; p=new MapObjects2.PointClass(); p=axMap2.ToMapPoint(e.x,e.y ); if (axMap1.Extent.IsPointIn(p)) { DragFeedbk .dragstart(axMap1.Extent ,axMap2,e.x,e.y ); </P> <P> } }</P> <P> private void axMap2_MouseMoveEvent(object sender, AxMapObjects2._DMapEvents_MouseMoveEvent e) { if (e.button==1) { DragFeedbk.dragmove(e.x,e.y );</P> <P> } }</P> <P> private void axMap1_MouseUpEvent(object sender, AxMapObjects2._DMapEvents_MouseUpEvent e) { }</P> <P> private void axMap2_MouseUpEvent(object sender, AxMapObjects2._DMapEvents_MouseUpEvent e) { axMap2.CtlRefresh(); axMap1.Extent=DragFeedbk.dragfinish(e.x,e.y );</P> <P> }</P> <P> } } </P> |
|
|
1楼#
发布于:2004-07-23 16:32
<P> 刚刚接触c# ,希望能够学到更多!</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
|
|
|
2楼#
发布于:2004-07-26 17:31
<P>用VC怎么写?谁来改写一下?</P><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em05.gif" />
|
|
3楼#
发布于:2004-07-26 23:11
<P>能改成VB吗??</P><img src="images/post/smile/dvbbs/em01.gif" />
|
|
4楼#
发布于:2006-07-07 08:02
太感谢了,我正需要。
|
|
5楼#
发布于:2006-07-07 08:05
<P>希望和用c#的朋友交流</P>
<P>qq:276446202</P><img src="images/post/smile/dvbbs/em04.gif" /> |
|