Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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();
    }

EDIT: 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;
    }
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

It stills draws all the rectangles, but I still need a way to clean them.

For the linesymbol, fillsymbol and symbol, set ROP2 = esriRasterOpCode.esriROPNotXOrPen.

share|improve this answer
    
kirk is the master of arcObjects :P –  George Aug 27 '10 at 14:32
add comment

I created a MeaureAreaTool using this sample Sample: Custom subtyped command and tool I don't get any problems with the redraw of the Polygon. Mayby you can get any ideas from my code.

Private m_polygonFeedback As INewPolygonFeedback
Private m_screenDisplay As IScreenDisplay

Private m_hookHelper As IHookHelper


Public Overrides Sub OnCreate(ByVal hook As Object)
If (m_hookHelper Is Nothing) Then m_hookHelper = New HookHelperClass

If Not hook Is Nothing Then
m_hookHelper.Hook = hook
End If
End Sub

Public Overrides Sub OnClick()
m_screenDisplay = m_hookHelper.ActiveView.ScreenDisplay
End Sub

Public Overrides Sub OnDblClick()
Dim polygon As IPolygon = m_polygonFeedback.Stop()
MsgBox("Area: " & CType(polygon, IArea).Area)
m_polygonFeedback = Nothing
End Sub

Public Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
If Button = 1 Then
Dim cursorPoint As ESRI.ArcGIS.Geometry.IPoint = m_screenDisplay.DisplayTransformation.ToMapPoint(X, Y)

If m_polygonFeedback Is Nothing Then
m_polygonFeedback = New NewPolygonFeedbackClass()
m_polygonFeedback.Display = m_screenDisplay

m_polygonFeedback.Start(cursorPoint)
Else
m_polygonFeedback.AddPoint(cursorPoint)
End If

End If
End Sub

Public Overrides Sub OnMouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
If Not m_polygonFeedback Is Nothing Then
Dim cursorPoint As ESRI.ArcGIS.Geometry.IPoint = m_screenDisplay.DisplayTransformation.ToMapPoint(X, Y)
m_polygonFeedback.MoveTo(cursorPoint)
End If
End Sub
share|improve this answer
add comment

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.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Display_feedback/000100000m9s000000/

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?

share|improve this answer
add comment

Your Answer

 
discard

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.