WPF gets screen resolution (get maximum width), etc.

Source: Internet
Author: User

Original: WPF gets screen resolution (get maximum width), etc.

Double x = systemparameters.workarea.width;//Gets the screen work area width double y = systemparameters.workarea.height;// Get screen work area height double x1= systemparameters.primaryscreenwidth;//Get screen overall width double y1 = systemparameters.primaryscreenheight ;//Get the overall height of the screen this. width = x1;//Sets the form width of this. Height = y1;//Set the form height

C # automatically adapts to screens based on different screen resolutions
C # automatically adapts to screens based on different screen resolutions

------Solution--------------------------------------------------------
Use TableLayoutPanel Layout + to set the Dock Anchor property.
------Solution--------------------------------------------------------
If only the component location, you can set the dock and anchor, etc.
If there are other special requirements, it is necessary to calculate some properties according to the actual resolution
------Solution--------------------------------------------------------
The form's windowstate is set to maximized and automatically fills the screen when loaded.
If you want to do other things, rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen;
Screen width =rect.width, height =rect.height

According to the WPF outsourcing widget, it is generally not necessary to explicitly position the window on the screen. Instead, simply set the WindowState property to normal and ignore all other details. On the other hand, it is very rare to set the Windowstartuplocation property to manual and use the Left property and the right property to explicitly set the position of the window.

There are times when you need to focus more on choosing locations and dimensions for Windows. For example, if you create a window that is too large to use a low-resolution display, you will get into trouble. If you use a single-window application, the best solution is to create a window that can change the size. If you use an application with several floating windows, the problem is not so simple.

According to the WPF outsourcing company, it is possible to limit the size of the window to support the smallest display, but this can make high-end users frustrated (they are specifically buying a better display for more information on the screen at a time). In this case, you typically want to determine the optimal position of the window at run time. To do this, you need to use the System.Windows.SystemParameters class to retrieve basic information about the actual state of the screen.

The SystemParameters class contains a number of static properties, from which you can get information about system settings. For example, you can use the SystemParameters class to determine whether a user has hot tracking enabled, display window content options when dragging, and other options. For Windows, the SystemParameters class is especially useful because it provides two properties that give you the current screen resolution:

The Fullprimaryscreenheight property and the Fullprimaryscreenwidth property. Both of these properties are very simple, and here are some of the demo code (locating the window in the middle of the screen at run time):

Double Screeheight = systemparameters.fullprimaryscreenheight;double Screewidth = Systemparameters.fullprimaryscreenwidth;this. Top = (screenheight-this. Height)/2;this. left = (screenwidth-this. Width)/2;

WPF outsourcing experts understand that while using the Code and setting the window's WindowState property to the Centerscreen effect is the same, the use of code has the flexibility to implement different positioning logic, and it can be executed at the right time.

A better choice is to use the Systemparameters.workarea rectangle so that the window is in the center of the available screen area. The work area does not include areas that dock the taskbar (and other toolbars that are docked to the desktop).

Double Workheight = systemparameters.workarea.height;double Workwidth = systemparameters.workarea.width;this. Top = (workheight-this. Height)/2;this. left = (workwidth-this. Width)/2;

Attention:

There is a small drawback to both of these sample code. When the top property is set for a window, the window is already visible and the window is immediately moved and refreshed. The same procedure occurs when you set the Left property with the following line of code. As a result, visually sensitive users will see two of times the window moves. Unfortunately, the window class does not provide a way to set both positional properties. The only workaround is to have the window positioned before it is created by calling the show () method or the ShowDialog () method.

WPF gets screen resolution (get maximum width), etc.

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.