3

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.

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?

Ian Turton
84k6 gold badges93 silver badges190 bronze badges
asked Aug 25, 2010 at 20:47

3 Answers 3

5

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.

answered Aug 25, 2010 at 21:29
0
1

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
answered Aug 25, 2010 at 21:21
-1
 public override void OnMouseDown(int Button, int Shift, int X, int Y)
 {
 if (Button == 2)
 {
 **m_activeview.ScreenDisplay.Invalidate(null, true, m_activeview.get_ScreenCacheID(esriViewDrawPhase.esriViewGraphics, null));**
 }
}
Hasan Mustafa
3,3361 gold badge15 silver badges41 bronze badges
answered May 11, 2016 at 9:55
1
  • Please provide more info to explain your answer rather than just some code. Commented May 11, 2016 at 10:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.