Window ActualTop, ActualLeft

前端 未结 4 1201
小蘑菇
小蘑菇 2020-12-02 02:11

What is the correct way to retrieve a window\'s position in WPF?

Here\'s some attempts I made. First attempt, the obvious

Point GetPosition(Window wi         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-02 02:50

    Yes, awkward. You've got bigger problems, (0, 0) won't be valid even on the primary monitor if the user put the taskbar on the left or the top. Like I did. You can get help from the Windows Forms Screen class. Use its FromPoint() method, then the WorkingArea property. Or the Bounds property if you allow the window to go full-screen.

    Personally, I'd just P/Invoke GetWindowRect().

提交回复
热议问题