With WinForms, is there a way to get a warning about the location of the control relative to the screen?
Say you have a form with a button on it, and you would like to know when the button moves from the current pixel location on the screen. If the button is moved to another place in the parent form, you can obviously use the LocationChanged event, but if the form is moved by the user, how do you know that the button is visually moved?
In this simplified case, the quick answer is to track Form LocationChanged and SizeChanged events, but there can be an arbitrary number of nesting levels, so monitoring these events for each parent up the chain to the primary form is not possible. Using a timer to check if the location has changed is also similar to cheating (bad way).
Short version: Given only an arbitrary Control object, is there a way to find out when this control location changes on the screen without knowing the control parent hierarchy?
Illustration on request:

Note that this concept of βpinningβ is an existing possibility, but currently it requires knowledge of the parent form and how the child control behaves; this is not the problem i am trying to solve. I would like to encapsulate this control tracking logic in an abstract form that pin-able Forms can inherit. Is there any message magic I can use to know when a control moves on the screen without having to deal with all the complicated parental tracking?
roken
source share