Hello,
is there an example of a simple PolygonDrawingTool with Line
style? I try to modify the class of DrawDemo4 without success. I get an line polygon but always with 2 points more at the start and end point. If i click 3 times for example, i get an polygon with 5 points. The points get visible if i try to move the start point or the last point.
Can anybody help me with this?
Thanks a lot,
Andreas
<Serializable()> Public Class PolygonDrawingTool Inherits GoTool Public Sub New(ByVal view As GoView) MyBase.new(view) End Sub Public Overrides Sub Start() MainForm.App.SetStatusMessage("Drawing mode -- click to add points to a new Polygon, Enter or Escape to stop") Me.View.Cursor = Cursors.Cross End Sub Public Overrides Sub [Stop]() If Not (myPolygon Is Nothing) Then myPolygon.Remove() myPolygon = Nothing End If Me.View.Cursor = Me.View.DefaultCursor MainForm.App.SetStatusMessage("Stopped drawing mode") End Sub Public Overrides Sub DoMouseDown() If Me.LastInput.DoubleClick Then Return End If If (myPolygon Is Nothing) Then ' create a new Polygon starting at the first mouse down point myPolygon = New GoPolygon() myPolygon.Style = GoPolygonStyle.Line myPolygon.AddPoint(Me.FirstInput.DocPoint) Me.View.Layers.Default.Add(myPolygon) End If myPolygon.AddPoint(Me.LastInput.DocPoint) End Sub Public Overrides Sub DoMouseMove() If Not (myPolygon Is Nothing) Then Dim numpts As Integer = myPolygon.PointsCount If (numpts >= 1) Then Dim Start As PointF = myPolygon.GetPoint(numpts - 1) Dim [end] As PointF = Me.LastInput.DocPoint myPolygon.SetPoint(numpts - 1, [end]) End If End If End Sub Public Overrides Sub DoMouseUp() ' don't call the base functionality, which assumes mouse up stops the tool If Me.LastInput.DoubleClick Then FinishPolygon() End If End Sub Private Sub FinishPolygon() If (Not (myPolygon Is Nothing) AndAlso myPolygon.PointsCount > 2) Then StartTransaction() ' make the final segment go back to the first point Me.LastInput.DocPoint = myPolygon.GetPoint(0) DoMouseMove() ' now move the Polygon from the view to the document myPolygon.Remove() Me.View.Document.Add(myPolygon) ' and make it selected Me.View.Selection.Select(myPolygon) myPolygon = Nothing Me.TransactionResult = "New Polygon" StopTransaction() StopTool() End If End Sub Private myPolygon As GoPolygon = Nothing End Class