Problem summary:
I’m overriding GoTextNode. I’m trying to supply an alternate rendering of the text by overriding the Paint() and ComputeBounds() methods. However, this seems to break the selection tool.
Example:
This is the code for a node which overrides GoTextNode. There’s a
custom Paint() function, and a custom ComputeBounds() function. Paint
happily paints the big red square created in the ctor. ComputeBounds
happily gives it enough space to be drawn. But the selection tool does
not allow you to select the red square; it seems to use the underlying
mybase.ComputeBounds function, or something close…
Imports Northwoods.Go
Public Class GoBadSelectionNode
Inherits GoTextNode
Dim _picture As Image
Sub New()
’ Set some node text
Me.Text = “short”
’ create a big red square
_picture = New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(_picture)
g.Clear(Color.Red)
’ invalidate the bounds to force a recalc
Me.InvalidBounds = True
End Sub
Public Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal view As Northwoods.Go.GoView)
g.DrawImage(_pic ture, Me.Bounds.Left, Me.Bounds.Top, Me.Bounds.Width,
Me.Bounds.Height)
End Sub
Protected Overrides Function ComputeBounds() As System.Drawing.RectangleF
Dim baseRect As RectangleF = MyBase.ComputeBounds()
If _picture Is Nothing Then
&nbs p; '
this is necessary because ComputeBounds is called on mybase.New(),
before _picture has been set.
Return baseRect
Else
Return New RectangleF(baseRect.X, baseRect.Y, _picture.Width,
_picture.Height)
End If
End Function
End Class
I’m adding one such node to a GoView with the call
GoView1.Document.Add(New GoBadSelectionNode)
Question:
Have I missed something? Is there something I have to do to get the selection tool to select within it’s new bounds?
Thanks for any light you might be able to shed on it…
Steve