How can I find the position of a maximized window?

前端 未结 7 1542
走了就别回头了
走了就别回头了 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:46

    I finally found a solution working for me:

    private System.Drawing.Rectangle getWindowRectangle()
    {
        System.Drawing.Rectangle windowRectangle;
    
        if (this.WindowState == System.Windows.WindowState.Maximized)
        {
            /* Here is the magic:
             * Use Winforms code to find the Available space on the
             * screen that contained the window 
             * just before it was maximized
             * (Left, Top have their values from Normal WindowState)
             */
            windowRectangle = System.Windows.Forms.Screen.GetWorkingArea(
                new System.Drawing.Point((int)this.Left, (int)this.Top));
        }
        else
        {
            windowRectangle = new System.Drawing.Rectangle(
                (int)this.Left, (int)this.Top,
                (int)this.ActualWidth, (int)this.ActualHeight);
        }
    
        return windowRectangle;
    }
    

提交回复
热议问题