Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
995
How to find all nodes within rectangle bounds?
posted

I am implementing a solution for a cursor drag selection of nodes within a visible rectangle, just like we do in Windows Explorer with files and folders. I have the rectangle part working and have some slick method of getting the nodes on the edge of the rectangle. However, if my rectangle is dragged past the nodes I cannot see them.

I am pretty sure there is a way to determine if a control falls within the bounds of a rectangle. Is there a way to do this with the tree nodes? I can use GetNodeFromPoint but only when I have a specific point. Is there a GetNodeLocation and then compare that to the bounds of the rectangle?

 Any points on this would be great. Even just how to determine if a specific location falls within the rectangle location. Thanks.

Parents
  • 995
    posted

    I figured it out. Took a little math and problem solving. I was hoping there was some kind of Rectangle.Compare function but unfortunately not. Here is the sub routine. Make sure the rectangle bounds you pass in are according to the ultratree control and not the screen coordinates.

     

    Public Function NodeIsInBounds(ByVal n As UltraTreeNode, ByVal rec As Rectangle) As Boolean

    'GET THE UI ELEMENT FOR THE NODE

    '

    Dim indent As Integer = 20 'ACCOUNTS FOR THE INDENTION OF THE NODES

    If n.UIElement.Rect.X + indent >= rec.X AndAlso n.UIElement.Rect.Y <= rec.Y + rec.Height AndAlso n.UIElement.Rect.Y + n.UIElement.Rect.Height >= rec.Y AndAlso Not (n.UIElement.Rect.X + indent > rec.X + rec.Width) Then

    Return True

    End If

    If n.UIElement.Rect.X + n.UIElement.Rect.Width >= rec.X AndAlso n.UIElement.Rect.Y <= rec.Y + rec.Height AndAlso n.UIElement.Rect.Y >= rec.Y AndAlso Not (n.UIElement.Rect.X + indent > rec.X + rec.Width) Then

    Return True

    End If

    If n.UIElement.Rect.X + n.UIElement.Rect.Width >= rec.X AndAlso n.UIElement.Rect.Y + n.UIElement.Rect.Height >= rec.Y AndAlso Not (n.UIElement.Rect.Y > rec.Y + rec.Height) AndAlso Not (n.UIElement.Rect.X + indent > rec.X + rec.Width) Then

    Return True

    End If

    Return False

    End Function

Reply Children