代码改变世界

获取屏幕的大小

2013-10-14 15:50  糯米粥  阅读(557)  评论(0编辑  收藏  举报

js获取屏幕的宽度 高度

window.screen:包含有关客户的屏幕和显示性能的信息。
 window.screenX:窗口X坐标
window.screenY:窗口Y坐标

 

            //我电脑的分辨率是1920*1080 也就是width:1920 height:1080 那么

            // 获取工作区域 。也就是高度不包括下面的任务栏  Windows需要添加引用 System.Windows.Forms
            int i = System.Windows.Forms.SystemInformation.WorkingArea.Width; //1920
            int b = System.Windows.Forms.SystemInformation.WorkingArea.Height; //1040

            //js获取工作区域的方法,
            window.screen.availHeight //1040

            window.screen.availWidth  //1920

            //以下结果相同。获取分辨率 。是屏幕的高度和宽度(包括任务栏高度)  Rectangle的命名空间:using System.Drawing;
            Rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen;
            int width = rect.Width; //1920
            int height = rect.Height; //1080

            System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.PrimaryScreen;
            System.Drawing.Rectangle rct = screen.Bounds;
            int k  = rct.Width; //1920
            int kk = rct.Height; //1080