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.