How to determine the screen width/height using C#

前端 未结 6 528
再見小時候
再見小時候 2021-02-03 23:48

I want to set the width & height of a Window dynamically based on the user screens maximum width/height. How can I determine this programmatically?

6条回答
  •  臣服心动
    2021-02-04 00:30

    I couldn't use any of the solutions above under .NET 4.0.30319.42000 with Windows 10 Enterprise when calling it from the Ranorex Studio 8.0.1+git.8a3e1a6f, so I used the line

    using WinForms = System.Windows.Forms;
    […]
                    SetWindowPos(processes[0].MainWindowHandle,
                        0,
                        y,
                        x,
                        WinForms.SystemInformation.PrimaryMonitorSize.Width,
                        WinForms.SystemInformation.PrimaryMonitorSize.Height,
                        SWP.SHOWWINDOW);
    

提交回复
热议问题