Csharp,Javascript 获取显示器的大小的几种方式

Csharp,Javascript 获取显示器的大小的几种方式 代码
 1  <% @ Page Language = " C# "  AutoEventWireup = " true "  CodeBehind = " WebForm1.aspx.cs "  Inherits = " DynamicScreens.WebForm1 "  ResponseEncoding = " utf-8 " %>
 2 
 3  <! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
 4 
 5  < html xmlns = " http://www.w3.org/1999/xhtml "   >
 6  < head runat = " server " >
 7  < meta http - equiv = " Content-Type "  content = " text/html; charset=utf-8 " />
 8       < title > 获取显示器大小 </ title >
 9         < script language = " javaScript "  type = " text/javaScript " >
10         // Geovin Du 涂聚文 2010-09-21
11          function displayScreenSize()
12          {          
13              document.getElementById( ' sheight ' ).value = window.screen.height + " + " + window.screen.width;
14           }
15  </ script >
16  </ head >
17  < body  onload = " displayScreenSize(); " >
18       < form id = " form1 "  runat = " server " >
19       < div >
20           < asp:TextBox ID = " sheight "  runat = " server " ></ asp:TextBox >         
21           < asp:TextBox ID = " TextBox1 "  runat = " server " ></ asp:TextBox >
22           < asp:TextBox ID = " TextBox2 "  runat = " server " ></ asp:TextBox >
23           < asp:TextBox ID = " TextBox3 "  runat = " server " ></ asp:TextBox >
24           < asp:ListBox ID = " ListBox1 "  runat = " server " ></ asp:ListBox >
25           </ div >
26       </ form >
27  </ body >
28  </ html >

 

Csharp,Javascript 获取显示器的大小的几种方式 代码
 1  using  System;
 2  using  System.Data;
 3  using  System.Configuration;
 4  using  System.Collections;
 5  using  System.Web;
 6  using  System.Web.Security;
 7  using  System.Web.UI;
 8  using  System.Web.UI.WebControls;
 9  using  System.Web.UI.WebControls.WebParts;
10  using  System.Web.UI.HtmlControls;
11  using  System.Text;
12  using  System.IO;
13  using  System.Runtime;
14  using  System.Management;
15  using  System.Windows.Forms;
16 
17  namespace  DynamicScreens
18  {
19       public   partial   class  WebForm1 : System.Web.UI.Page
20      {
21           ///   <summary>
22           ///  Geovin Du 涂聚文 2010-09-21
23           ///  获取显示器的大小
24           ///   </summary>
25           ///   <param name="sender"></param>
26           ///   <param name="e"></param>
27           protected   void  Page_Load( object  sender, EventArgs e)
28          {
29              Session.CodePage  =   65001 ;
30              
31               int  deskHeight  =  Screen.PrimaryScreen.Bounds.Height;
32               int  deskWidth  =  Screen.PrimaryScreen.Bounds.Width;
33 
34               this .TextBox1.Text  =  deskHeight.ToString()  +   " : "   +  deskWidth.ToString();
35               Screen[] screens1  =  Screen.AllScreens;  // 显示设备的集合
36                string  screenWidth  =  screens1[ 0 ].Bounds.Width.ToString();  //  获取第一个显示设备
37                string  screenHeight  =  screens1[ 0 ].Bounds.Height.ToString();
38                this .TextBox2.Text  =  screenHeight  +   " : "   +  screenWidth;
39                int  aaaa  =  screens1[ 0 ].WorkingArea.Height;     // 获取桌面的工作区   高度
40                int  bbbb  =  screens1[ 0 ].WorkingArea.Width;        // 获取桌面的工作区 宽度
41                this .TextBox3.Text  =  aaaa.ToString()  +   " : "   +  bbbb.ToString();
42 
43 
44                int  index;
45                int  upperBound;
46 
47                //  Gets an array of all the screens connected to the system.
48 
49               Screen[] screens  =  Screen.AllScreens;
50               upperBound  =  screens.GetUpperBound( 0 );
51 
52                for  (index  =   0 ; index  <=  upperBound; index ++ )
53               {
54 
55                    //  For each screen, add the screen properties to a list box.
56 
57                   ListBox1.Items.Add( " Device Name:  "   +  screens[index].DeviceName);
58                   ListBox1.Items.Add( " Bounds:  "   +  screens[index].Bounds.ToString());
59                   ListBox1.Items.Add( " Type:  "   +  screens[index].GetType().ToString());
60                   ListBox1.Items.Add( " Working Area:  "   +  screens[index].WorkingArea.ToString());
61                   ListBox1.Items.Add( " Primary Screen:  "   +  screens[index].Primary.ToString());
62 
63               }
64 
65 
66          }
67      }
68  }

 

你可能感兴趣的:(JavaScript)