07. Obtain the screen resolution on Windows 10 and set the Windows10 resolution.

Source: Internet
Author: User

07. Obtain the screen resolution on Windows 10 and set the Windows10 resolution.

 

Because on win10, when the app is running, the screen is not fully occupied by default, and windows runtime is not available currently.

Screen Size api. You can obtain the screen size in the desktop win32 api, but it cannot be used directly because it is a restricted api.

 

Screen size of my current PC:

 

Method 1: Obtain the screen resolution by calling javascript in the WebView control:

Put a WebView control on the page:

 <WebView x:Name="webView"  LoadCompleted="WebView_LoadCompleted"/>

  

In the page loading completion event, add the js Code:

Private void WebView_test_Loaded (object sender, RoutedEventArgs e) {// webView. navigateToString ("<script>" + // "window. onload = function loaded () {"+ //" document. write ('screen resolution: '+ window. screen. width + 'X' + window. screen. height);} "+ //" </script> ");
// In the WebView control, add the webView method for obtaining the screen resolution. navigateToString ("


Run the app:

 

 

Method 2: By default, when the app is started for the first time, the window is in full screen mode and the size of the window is obtained.

In full screen mode, the window size is the screen size. You can store the obtained size in Settings

Later. The disadvantage is that the first full screen startup by default may not be the behavior the user wants and cannot force the user.

Call ApplicationView api:

Windows. UI. viewManagement. applicationView view = Windows. UI. viewManagement. applicationView. getForCurrentView (); // There is a "try" word in the method name, that is, the view fails to display full screen. tryEnterFullScreenMode (); // If the screen size is read immediately, it is not full screen. After a full screen at a specific time point, obtain the screen size Debug. WriteLine (Window. Current. Bounds. Width + "X" + Window. Current. Bounds. Height );

 

Other ApplicationView operations:

Windows. UI. viewManagement. applicationView view = Windows. UI. viewManagement. applicationView. getForCurrentView (); private void Button_full_Click (object sender, RoutedEventArgs e) {Debug. writeLine ("full screen operation:" + view. tryEnterFullScreenMode (); bool isFull = view. isFullScreen;} private void Button_exitFull_Click (object sender, RoutedEventArgs e) {view. exitFullScreenMode (); Debug. writeLine ("exit full screen");} private void Button_resize_Click (object sender, RoutedEventArgs e) {Debug. writeLine ("change view:" + view. tryResizeView (new Size (1200,900);} private void Button_boundsMode_Click (object sender, RoutedEventArgs e) {if (view. desiredBoundsMode = Windows. UI. viewManagement. applicationViewBoundsMode. useVisible) {view. setDesiredBoundsMode (Windows. UI. viewManagement. applicationViewBoundsMode. useCoreWindow); Debug. writeLine ("set to: ApplicationViewBoundsMode. useCoreWindow ");} else {view. setDesiredBoundsMode (Windows. UI. viewManagement. applicationViewBoundsMode. useVisible); Debug. writeLine ("set to: ApplicationViewBoundsMode. useVisible ") ;}}// set the window size. private void Button_mini_size_Click (object sender, RoutedEventArgs e) {view. setPreferredMinSize (new Size (100,100);} private void Button_standard_overlays_Click (object sender, RoutedEventArgs e) {view. showStandardSystemOverlays ();} // obtain the size and position of the view. private void Button_VisibleBounds_Click (object sender, RoutedEventArgs e) {Rect rect = view. visibleBounds; Debug. writeLine (string. format ("VisibleBounds ---- Left: {0}, Right: {1}, Width: {2}, Height: {3}", rect. left, rect. right, rect. width, rect. height);} private void Button_PreferredLaunchViewSize_Click (object sender, RoutedEventArgs e) {Windows. UI. viewManagement. applicationView. preferredLaunchViewSize = new Size (800,800);} // private void Button_ApplicationViewState_Click (object sender, RoutedEventArgs e) {Debug. writeLine ("ApplicationViewState:" + Windows. UI. viewManagement. applicationView. value. toString ();} private void Button_global_back_Click (object sender, RoutedEventArgs e) {var curView = Windows. UI. core. systemNavigationManager. getForCurrentView (); if (curView. appViewBackButtonVisibility = Windows. UI. core. appViewBackButtonVisibility. visible) {curView. appViewBackButtonVisibility = Windows. UI. core. appViewBackButtonVisibility. collapsed;} else {curView. appViewBackButtonVisibility = Windows. UI. core. appViewBackButtonVisibility. visible ;}}View Code

 

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.