天天看點

Silverlight擷取螢幕分辨率

/// <summary>

    /// 浏覽器螢幕資訊類

    /// </summary>

    public class Browser

    {

        /// <summary>  

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

        /// </summary>  

        static Browser()

        {

            _isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape");

        }

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

        private static bool _isNavigator;

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

        private static ScriptObject Screen

            get

            {

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

                if (screen == null)

                {

                    throw new InvalidOperationException();

                }

                return screen;

            }

        /// Gets the window object's client width  

        public static double ClientWidth

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

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

        /// Gets the window object's client height  

        public static double ClientHeight

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

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

        /// Gets the current horizontal scrolling offset  

        public static double ScrollLeft

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

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

        /// Gets the current vertical scrolling offset  

        public static double ScrollTop

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

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

        /// Gets the width of the entire display  

        public static double ScreenWidth

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

        /// Gets the height of the entire display  

        public static double ScreenHeight

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

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

        /// or task bar  

        public static double AvailableScreenWidth

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

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

/// or task bar  

        public static double AvailableScreenHeight

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

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

        public static double ScreenPositionLeft

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

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

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

        public static double ScreenPositionTop

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

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

    }

繼續閱讀