shubumpkin wrote:
am finding that the top attribute of a control (in this case a tree view control) returns top values relative to its panel.
The Location (Left, Top) is alway s relative to the controls parent container. To get to the form, you have to follow the Parent property of your control to it's parent contain, and keep following it up until Parent returns nothing. When you find that, your code is looking at the Form. A quick and dirty method to do this would be something like:
Public Shared Function GetTopContainerOfControl(ByRef childControl As Control) As Control
Dim currentControl As Control = c
While (currentControl.Parent IsNot Nothing)
currentControl = currentControl.Parent
End While
Return currentControl
End Function
This quick example doesn't have any error handling and CAN go on forever if there is a mistake in the control parent/child chain as an infinite loop will result. Since this doesn't use recursion, there is no danger of overflowing the stack, not matter how many levels deep a control is.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007