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.

  • Did you try setting m_hookHelper.ActiveView.ScreenDisplay.CancelTracker = esc; ? Commented Apr 17, 2012 at 21:34
  • Yes Kirk, but it didn't work either.
    – gumo
    Commented Apr 19, 2012 at 9:30
  • 1
    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
    Commented Apr 19, 2012 at 10:55
  • Thanks Petr, I wasn't quite sure, because it isn't a real answer.
    – gumo
    Commented Apr 19, 2012 at 13:47

3 Answers 3


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).

  • Thanks, Petr. I will try the display feedback. Btw. your display feedback link seems wrong. I guess you meant to link to IDisplayFeedback.
    – gumo
    Commented Apr 19, 2012 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
    Commented Apr 19, 2012 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;

  • 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
    Commented Apr 17, 2012 at 13:54

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.

  • How did you work around the WPF problem?
    – blah238
    Commented Apr 19, 2012 at 17:09
  • Unfortunatly I haven't found a solution yet.
    – gumo
    Commented Apr 20, 2012 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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