I have some code that I'm using to selecting features in a certain extent. I already rigged the tool properly, so it selected the objects as needed, but I want to draw interactively the selection box the user is making.
I'm using IScreenDisplay.DrawRectangle
method, but it pollutes the screen with many small rectangles. Is there a way to clear up the old drawings in the screen?
This Draw method is being called from a mouse move event. Any ideas?
Here are two methods I'm using to do the dirty work:
public override void OnMouseMove(int button, int shift, int x, int y)
{
if (button != 1)
return;
if (!_IsSelectOperation)
return;
endPoint = focusScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
envelope.PutCoords(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
DrawEnvelope(envelope, BuildSelectionSymbol(), focusScreenDisplay);
}
private void DrawEnvelope(IEnvelope envelope, ISymbol symbol, IScreenDisplay screenDisplay)
{
screenDisplay.StartDrawing(screenDisplay.WindowDC, 0);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawRectangle(envelope);
screenDisplay.FinishDrawing();
}
Here is the code for BuildSelectionSymbol
:
private ISymbol BuildSelectionSymbol()
{
IColor fillColor = new RgbColorClass();
fillColor.Transparency = 0;
IRgbColor outlineColor = new RgbColorClass();
outlineColor.Red = 0;
outlineColor.Green = 0;
outlineColor.Blue = 0;
ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Color = outlineColor as IColor;
lineSymbol.Width = 1;
lineSymbol.Style = esriSimpleLineStyle.esriSLSDash;
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = fillColor;
fillSymbol.Outline = lineSymbol;
fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
ISymbol symbol = fillSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNOP;
return symbol;
}
I already have the answer for this. I was using a normal envelope. The deal is that ESRI already has something to handle that for you and it's contained in INewEnvelopeFeedback class.
Actually, this interface got me where the code snippet in the question was. It stills draws all the rectangles, but I still need a way to clean them.
Any ideas?