Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a BaseTool for AX_MapControl and AX_PageLayoutControl that allows to draw a polyline via IRubberBand. But once the rubberband is started, you can't cancel it e.g. by hitting escape. I found ITrackCancel but unfortunatly no way to use it properly.

ITrackCancel2 esc = new CancelTrackerClass();
esc.CancelOnKeyPress = true;

IRubberBand2 rubberBand = new RubberLineClass();
IGeometry geometry = rubberBand.TrackNew(screenDisplay, null);
IPolyline polyline = (IPolyline)geometry;

How do I use ITrackCancel to cancel the rubberband tracking?

Update: ITrackCancel can be retrieved from IScreenDisplay but my m_hookHelper.ActiveView.ScreenDisplay.CancelTracker is null. I use the tool with AX_MapControl and AX_PageLayoutControl.

Update 2: I found out, that even Esris own tools like esriControls.ControlsNewLineTool can't be canceled with escape in my application. Maybe there is a deeper flaw somewhere. Going to dive deeper into it...

Update 3 (Solution): There is a glitch in my WPF application. It seems, that on startup no key events arrive the MapControl until you change the window size once. So this is not a problem with ITrackCancel but with the interaction between WPF and ArcEngine. Thanks anyways for your help.

share|improve this question
Did you try setting m_hookHelper.ActiveView.ScreenDisplay.CancelTracker = esc; ? – Kirk Kuykendall Apr 17 '12 at 21:34
Yes Kirk, but it didn't work either. – gumo Apr 19 '12 at 9:30
Reaction to update 3: I guess now you should either mark one of answers as correct or post your own answer (and mark it as correct). – Petr Krebs Apr 19 '12 at 10:55
Thanks Petr, I wasn't quite sure, because it isn't a real answer. – gumo Apr 19 '12 at 13:47

The documentation for rubber bands suggests that they should support cancelling via pressing the Esc key.

If that really does not work for you, consider using a display feedback instead, e.g. the NewLineFeedback. Display feedbacks are a bit more involved than rubber bands, but they are not necessarily that much difficult to use. Plus, you can Stop most feedbacks at will at any time (e.g. upon pressing Esc).

share|improve this answer
Thanks, Petr. I will try the display feedback. Btw. your display feedback link seems wrong. I guess you meant to link to IDisplayFeedback. – gumo Apr 19 '12 at 9:29
Using NewLineFeedback definitly works. I hook up the tools OnKeyDown event to escape on Escape. Anyways, the problem wasn't with ITrackCancel at all, see my question update 3. – gumo Apr 19 '12 at 10:33

ScreenDisplay coclass is implementing IScreendisplay which has a CancelTracker member IScreenDisplay Interface ..So it should get the escape button press as far as i know..the below code works..

public override void OnMouseDown(int Button, int Shift, int X, int Y)

            IMxDocument pMxDoc = (IMxDocument)m_application.Document ;
            IGraphicsContainer pGraCont = (IGraphicsContainer)pMxDoc.ActiveView;
            IRubberBand pRubberLine = new RubberLineClass();
            IElement pElement;
            IPolyline pPolyline = (IPolyline)pRubberLine.TrackNew(pMxDoc.ActiveView.ScreenDisplay,null);
            pElement = new LineElementClass();
            pElement.Geometry = pPolyline;

share|improve this answer
My Tool is for AX_MapControl and AX_PageLayoutControl so I tried your code with my IHookHelper instead of your IMxDocument but it didn't work. m_hookHelper.ActiveView.ScreenDisplay.CancelTracker is null. So it seems to be different somehow. – gumo Apr 17 '12 at 13:54
up vote 1 down vote accepted

Both suggested answers do work fine. I had another failure in my WPF application, that caused this behavior. It seems, that after the start no key event arrived the MapControl until one changes the window size once. After that all worked as exspected. So it was not a problem with ITrackCancel but with the interaction between WPF and ArcEngine.

share|improve this answer
How did you work around the WPF problem? – blah238 Apr 19 '12 at 17:09
Unfortunatly I haven't found a solution yet. – gumo Apr 20 '12 at 6:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.