moelgaard

problem with INewEnvelopeFeedback

Discussion created by moelgaard on Apr 4, 2011
Hi everyone.

I´m currently developing a tool which enables the user to "draw" a box and use it as a way of selecting features. The code inherits BaseCommand, ICommand, ITool and the code is like this

        public void OnMouseDown(int button, int shift, int x, int y)
        {
            if (modFeature.bDBOpen)
            {
                if (button != 1)  //(int)MouseButtons.Left)
                { return; }
                pMxDoc = pApp.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument;
                pActiveView = pMxDoc.ActiveView;
                pMxDoc.ActiveView.FocusMap.ClearSelection();
                // Store current point, set mousedown flag  
                pPointFrom = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                pFeedBack = new ESRI.ArcGIS.Display.NewEnvelopeFeedback();
                pFeedBack.Display = pActiveView.ScreenDisplay;
                pFeedBack.Start(pPointFrom);
                pFeedBack.MoveTo(pPointFrom);
            }
        }

        public void OnMouseMove(int button, int shift, int x, int y)
        {
            if ((pFeedBack == null) || (button != 1))
            { return; }
            pPointTo = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            pFeedBack.MoveTo(pPointTo);
            System.Windows.Forms.Application.DoEvents();
        }

        public void OnMouseUp(int button, int shift, int x, int y)
        {
            if (button != 1)  //(int)MouseButtons.Left)
            { return; }
            pPointTo = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            pFeedBack.Stop();
            pFeedBack = null;
            modFeature.boxSelection(pPointFrom, pPointTo);
            pActiveView.Refresh();
            pPointFrom = null;
            pPointTo = null;
            pFeedBack = null;
            base.m_checked = false;
        }

If the user hasn´t loaded a mxd, this works great. Once a .mxd is loaded the box tends to move in a north-east direction, so I´m guessing it has something to do with projections, but I´m not sure what to do.

Any suggestions/advice is most appreciated
/Kaare

Outcomes