How can I find the position of a maximized window?

前端 未结 7 1600
走了就别回头了
走了就别回头了 2020-12-30 05:23

I need to know the position of a window that is maximized.

WPF Window has Top and Left properties that specifies the window\'s location. However, if you maximize the

7条回答
  •  长情又很酷
    2020-12-30 05:57

    Universal one line answer working for all monitors and all high DPI variants:

    Point leftTop = this.PointToScreen(new Point(0, 0));
    

    This for example returns (-8, -8) for a window which is maximized on a 1920 wide screen whose ActualWidth returns 1936.

    Just a rant to the other answers: NEVER mix up logical 96 dpi WPF pixels (using double) with native real pixels (using int) - especially by just casting double to int!

提交回复
热议问题