Silverlight获取屏幕分辨率
2010-08-23 08:37
169 查看
/// <summary>
/// 浏览器屏幕信息类
/// </summary>
public class Browser
{
/// <summary>
/// During static instantiation, only the Netscape flag is checked
/// </summary>
static Browser()
{
_isNavigator = HtmlPage.BrowserInformation.Name.Contains("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");
}
}
}
/// 浏览器屏幕信息类
/// </summary>
public class Browser
{
/// <summary>
/// During static instantiation, only the Netscape flag is checked
/// </summary>
static Browser()
{
_isNavigator = HtmlPage.BrowserInformation.Name.Contains("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");
}
}
}
相关文章推荐
- Silverlight如何获取屏幕分辨率
- silverlight获取屏幕分辨率
- Android开发之如何获取Android手机屏幕的大小(分辨率、密度)
- WPF 获取屏幕分辨率
- Android获取屏幕分辨率
- Android获取屏幕分辨率及DisplayMetrics简介
- Android获取屏幕分辨率及DisplayMetrics
- VC获取屏幕分辨率大小
- Android开发之如何获取Android手机屏幕的大小(分辨率、密度)
- Android 获取屏幕分辨率
- robotium测试时获取Android手机屏幕的分辨率大小
- Android获取屏幕分辨率及DisplayMetrics简介
- android 获取屏幕的分辨率
- 获取屏幕分辨率
- Android获取屏幕分辨率及DisplayMetrics简介
- Python获取屏幕分辨率大小
- 获取屏幕的分辨率
- VC中怎么获取屏幕分辨率
- Silverlight获取屏幕的高与宽
- iphone中获取屏幕分辨率的方法