SRI.ArcGIS.Desktop.AddIns.Tool 鼠标事件

转自http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//000100000p3q000000
// Copyright 2012 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // using System; using System.Collections.Generic; using System.Text; using System.IO; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; namespace DisplayFeedbackSample { public class DisplayFeedbackSample : ESRI.ArcGIS.Desktop.AddIns.Tool { private INewEnvelopeFeedback NewEnvelopeFeedback; private IEnvelope feedbackEnv; private IElement feedbackElement; private IScreenDisplay feedbackScreenDisplay; private ISimpleLineSymbol feedbackLineSymbol; private ESRI.ArcGIS.Geometry.Point feedbackStartPoint; private ESRI.ArcGIS.Geometry.Point feedbackMovePoint; public DisplayFeedbackSample() { } protected override void OnUpdate() { Enabled = ArcMap.Application != null; } protected override void OnMouseDown(MouseEventArgs Args) { //initialize all the variables. feedbackEnv = new EnvelopeClass(); feedbackStartPoint = new ESRI.ArcGIS.Geometry.PointClass(); feedbackMovePoint = new ESRI.ArcGIS.Geometry.PointClass(); feedbackLineSymbol = new SimpleLineSymbolClass(); feedbackScreenDisplay = ArcMap.Document.ActiveView.ScreenDisplay; feedbackLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; //initialize a new Envelope feedback class and pass it the symbol and display NewEnvelopeFeedback = new NewEnvelopeFeedbackClass(); NewEnvelopeFeedback.Display = feedbackScreenDisplay; NewEnvelopeFeedback.Symbol = feedbackLineSymbol as ISymbol; //pass the start point from the mouse position, transforming it to an appropriate map point. feedbackStartPoint = feedbackScreenDisplay.DisplayTransformation.ToMapPoint(Args.X, Args.Y) as ESRI.ArcGIS.Geometry.Point; NewEnvelopeFeedback.Start(feedbackStartPoint); } protected override void OnMouseMove(MouseEventArgs Args) { //only pass the point if the mouse button is down if (Args.Button.ToString() == "Left") { //pass X and Y to feedbackMovePoint to transfer to NewEnvelopeFeedback feedbackMovePoint = feedbackScreenDisplay.DisplayTransformation.ToMapPoint(Args.X, Args.Y) as ESRI.ArcGIS.Geometry.Point; NewEnvelopeFeedback.MoveTo(feedbackMovePoint); } } protected override void OnMouseUp(MouseEventArgs Args) { //when mouse comes up, end the new envelope and pass it to feedbackEnv. feedbackEnv = NewEnvelopeFeedback.Stop(); //initialize a new RectangleElementClass feedbackElement = new RectangleElementClass(); //pass the new rectangle element, the geometry defined by our feedback object feedbackElement.Geometry = feedbackEnv; //make sure the element is activated in the current view feedbackElement.Activate(feedbackScreenDisplay); //now add the newly created element to the ActiveView with default symbology. ArcMap.Document.ActiveView.GraphicsContainer.AddElement(feedbackElement, 0); //and refresh the view so we can see the changes. ArcMap.Document.ActiveView.Refresh(); } } }

转载于:https://www.cnblogs.com/Joetao/articles/5697536.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值