Absolute screen coordinates of user control RRS feed

  • Question

  • Hi,


    How would I find out the absolute screen coordinates of the top left corner of a WPF user control please?


    The hierarchy is:

    Windows Forms Applciation > Main Form > Element Host > WPF User Control by the way.


    Thank you very much,


    Friday, May 9, 2008 6:43 AM


All replies

  • First of all, use the PointToScreen method of your WPF control to get a screen coordinate in WPF DPI-agnostic coordinates. Then you must obtain an HwndSource, which you can probably get from your ElementHost assuming it exposes an hwnd. Then you would use source.CompositionTarget.TransformToDevice.Transform(screenPoint) to convert into the same device coordinates that Win32 uses.


    Friday, May 9, 2008 8:25 AM
  • Thanks for your answer Tim.

    I expanded a bit on my question in this thread http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3319318&SiteID=1
    and also put a solution there in case somebody else has the same problem.

    The solution used TransformFromDevice instead of TransformToDevice to get the right coordinates by the way.

    Thanks again and all the best,
    Friday, May 9, 2008 6:53 PM