微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight如何获取屏幕分辨率

方法一:
 
/// <summary>

         /// 浏览器屏幕信息类

         /// </summary>

         public class browser

        {

                 /// <summary>        

                 /// During static instantiation,only the netscape flag is checked        

                 /// </summary>        

                 static browser()

                {

                        _isNavigator = HtmlPage.browser@R_231_404[email protected]( "netscape");

                }

                 /// <summary>        

                 /// Flag indicating Navigator/Firefox/Safari or Internet Explorer        

                 /// </summary>        

                 private static bool _isNavigator;

                 /// <summary>        

                 /// Provides quick access to the window.screen ScriptObject        

                 /// </summary>        

                 private static ScriptObject Screen

                {

                        get

                        {

                                ScriptObject screen = (ScriptObject)HtmlPage.Window.GetProperty( "screen");

                                 if (screen == null)

                                {

                                         throw new InvalidOperationException();

                                }

                                 return screen;

                        }

                }

                 /// <summary>        

                 /// Gets the window object's client width        

                 /// </summary>        

                 public static double ClientWidth

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "innerWidth")

                                        : ( double)HtmlPage.Document.Body.GetProperty( "clientWidth");

                        }

                }

                 /// <summary>        

                 /// Gets the window object's client height        

                 /// </summary>        

                 public static double ClientHeight

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "innerHeight")

                                        : ( double)HtmlPage.Document.Body.GetProperty( "clientHeight");

                        }

                }

                 /// <summary>        

                 /// Gets the current horizontal scrolling offset        

                 /// </summary>        

                 public static double ScrollLeft

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "pageXOffset")

                                        : ( double)HtmlPage.Document.Body.GetProperty( "scrollLeft");

                        }

                }

                 /// <summary>        

                 /// Gets the current vertical scrolling offset        

                 /// </summary>        

                 public static double ScrollTop

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "pageYOffset")

                                        : ( double)HtmlPage.Document.Body.GetProperty( "scrollHeight");

                        }

                }

                 /// <summary>        

                 /// Gets the width of the entire display        

                 /// </summary>        

                 public static double ScreenWidth

                {

                        get

                        {

                                 return ( double)Screen.GetProperty( "width");

                        }

                }

                 /// <summary>        

                 /// Gets the height of the entire display        

                 /// </summary>        

                 public static double ScreenHeight

                {

                        get

                        {

                                 return ( double)Screen.GetProperty( "height");

                        }

                }

                 /// <summary>        

                 /// Gets the width of the available screen real estate,excluding the dock        

                 /// or task bar        

                 /// </summary>        

                 public static double AvailableScreenWidth

                {

                        get

                        {

                                 return ( double)Screen.GetProperty( "availWidth");

                        }

                }

                 /// <summary>        

                 /// Gets the height of the available screen real estate,excluding the dock /// or task bar        

                 /// </summary>        

                 public static double AvailableScreenHeight

                {

                        get

                        {

                                 return ( double)Screen.GetProperty( "availHeight");

                        }

                }

                 /// <summary>        

                 /// Gets the absolute left pixel position of the window in display coordinates        

                 /// </summary>        

                 public static double ScreenPositionLeft

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "screenX")

                                        : ( double)HtmlPage.Window.GetProperty( "screenLeft");

                        }

                }

                 /// <summary>        

                 /// Gets the absolute top pixel position of the window in display coordinates        

                 /// </summary>        

                 public static double ScreenPositionTop

                {

                        get

                        {

                                 return _isNavigator ? ( double)HtmlPage.Window.GetProperty( "screenY")

                                        : ( double)HtmlPage.Window.GetProperty( "screenTop");

                        }

                }

        }

方法二:
                  
 double    screenWidth = ( double)HtmlPage.Window.Eval( "screen.Width");    
  double screenHeight = ( double)HtmlPage.Window.Eval( "screen.Height");    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐