I've written a function to create a polygon based on geometry collected from the IRubberBand interface as follows:
ITrackCancel esc = new CancelTrackerClass();
esc.CancelOnKeyPress = true;
esc.Reset();
ArcMap.Document.ActiveView.ScreenDisplay.CancelTracker = esc;
//MessageBox.Show("This will allow a key press to cancel the tracking if uncommented");
IRubberBand rubberBand = new RubberPolygonClass();
IScreenDisplay screenDisplay = ArcMap.Document.ActiveView.ScreenDisplay;
IGeometry geometry = rubberBand.TrackNew(screenDisplay, null);
I am attempting to cancel the tracking of the polygon (i.e. cancel the drawing operation) on key press. The above code will not cancel the tracking unless I insert a MessageBox display somewhere before the tracking begins. My guess is that this problem is somehow related to this issue: How to use ITrackCancel to escape IRubberBand track? . I'm also a bit skeptical of how I've hooked into the active view. If anyone could provide some insight on how to best cancel this operation without an awkward messagebox being involved I would certainly appreciate it.