Determine the screen on which the Window is located and the Window screen

Source: Internet
Author: User

Determine the screen on which the Window is located and the Window screen

Recently, a function is required to maximize the Window. If multiple monitors are used, the function is required to maximize the current display. Because the Window size is set based on the screen length and width, WindowState is not used. maximized, window. left does not know the value of this setting. Later, when debugging, we found that the X coordinates of the non-primary monitor were based on the primary screen. For example, if 2nd are the primary screen, the first screen X is-1600.

Foreach (System. windows. forms. screen screen in System. windows. forms. screen. allScreens) {if (winLeft> = screen. bounds. left & winLeft <= screen. bounds. left + screen. bounds. width) {return screen;} return System. windows. forms. screen. allScreens [0];

Later I found a more concise answer.

IntPtr handle = new WindowInteropHelper (window). Handle; return System. Windows. Forms. Screen. FromHandle (handle );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.