WPF determines the vertical screen state under Surface+win8

Source: Internet
Author: User

Today I'm doing a WPF program for surface2+win8.1, which fixes the resolution and height width, which means that the vertical screen mode is not supported directly.

When a device switches from a horizontal screen to a vertical screen, the WPF program becomes smaller, some controls are overwritten, and when you switch from the vertical screen to the horizontal screen, the program does not become the same size or the size of the vertical screen.
Note: Outside of the program is window, which is page, found that the page inside the control will be overwritten

But in the vertical screen mode how to prompt the user that?

The following method was found:

Add an event registration displaysettingschanged to your main form:

The code is as follows Copy Code

Microsoft.win32.systemevents.displaysettingschanged+=newsystem.eventhandler (DisplaySettingsChanged);

Then in the event to increase the judge is not the height is greater than the width that means the vertical screen.

The code is as follows Copy Code
Privatevoiddisplaysettingschanged (OBJECTSENDER,EVENTARGSE)
{
if (system.windows.systemparameters.primaryscreenheight>system.windows.systemparameters.primaryscreenwidth)
{
Runtheapplicationinportrait
This. width=1269;
This. height=699;
MessageBox.Show (The helper program does not support vertical work, please use it in horizontal mode.) ");
}
Else
{
This. width=1269;
This. height=699;
}
}

The normal working height and width of surface are: 1269*699.

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.