Form1.cs
上传用户:chinafred
上传日期:2007-08-14
资源大小:10127k
文件大小:11k
源码类别:

数据库编程

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. //using System.Diagnostics;
  8. using System.ServiceProcess;
  9. namespace ch4_7
  10. {
  11. /// <summary>
  12. /// Form1 的摘要说明。
  13. /// </summary>
  14. public class Form1 : System.Windows.Forms.Form
  15. {
  16. private System.Windows.Forms.GroupBox groupBox1;
  17. private System.Windows.Forms.Label label1;
  18. private System.Windows.Forms.Label label2;
  19. private System.Windows.Forms.Label label3;
  20. private System.Windows.Forms.Label label4;
  21. private System.Windows.Forms.Label label5;
  22. private System.Windows.Forms.Label label6;
  23. private System.Windows.Forms.Label label7;
  24. private System.Windows.Forms.Label label8;
  25. private System.Windows.Forms.Label label9;
  26. private System.Windows.Forms.Label label10;
  27. private System.Windows.Forms.Label label11;
  28. private System.Windows.Forms.Label label12;
  29. private System.Windows.Forms.Label label13;
  30. private System.Windows.Forms.Label label14;
  31. private System.Windows.Forms.Label label15;
  32. private System.Windows.Forms.Label label16;
  33. private System.Windows.Forms.GroupBox groupBox2;
  34. private System.Windows.Forms.ListBox listBox1;
  35. /// <summary>
  36. /// 必需的设计器变量。
  37. /// </summary>
  38. private System.ComponentModel.Container components = null;
  39. public Form1()
  40. {
  41. //
  42. // Windows 窗体设计器支持所必需的
  43. //
  44. InitializeComponent();
  45. Information();
  46. //
  47. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  48. //
  49. }
  50. private void Information()
  51. {
  52. //获取计算机名称
  53. this.label1.Text=SystemInformation.ComputerName;
  54. //获取用户名
  55. this.label2.Text=SystemInformation.UserName;
  56. //获取用户工作域名称
  57. this.label3.Text=SystemInformation.UserDomainName;
  58. //获取显示器分辨率
  59. this.label4.Text=SystemInformation.PrimaryMonitorSize.Width.ToString()+","+
  60.  SystemInformation.PrimaryMonitorSize.Height.ToString();
  61. //检查网络连接状态
  62. if (SystemInformation.Network==true)
  63. {
  64. this.label5.Text="已连接";
  65. }
  66. else
  67. {
  68.     this.label5.Text="未连接";
  69. }
  70. //获取启动模式
  71. this.label6.Text=SystemInformation.BootMode.ToString();
  72. //获取使用的操作系统的Platform和版本值
  73. this.label13.Text=Environment.OSVersion.Platform.ToString();
  74. this.label14.Text=Environment.OSVersion.Version.ToString();
  75.             
  76. ServiceController[] services;
  77. //检索计算机上的所有服务
  78. services = ServiceController.GetServices();
  79. //将服务的名称添加到ListBox中
  80. for (int i = 0; i <  services.Length; i++)
  81. {
  82. this.listBox1.Items.Add(services[i].ServiceName);
  83. }
  84. }
  85. /// <summary>
  86. /// 清理所有正在使用的资源。
  87. /// </summary>
  88. protected override void Dispose( bool disposing )
  89. {
  90. if( disposing )
  91. {
  92. if (components != null) 
  93. {
  94. components.Dispose();
  95. }
  96. }
  97. base.Dispose( disposing );
  98. }
  99. #region Windows Form Designer generated code
  100. /// <summary>
  101. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  102. /// 此方法的内容。
  103. /// </summary>
  104. private void InitializeComponent()
  105. {
  106. this.groupBox1 = new System.Windows.Forms.GroupBox();
  107. this.label1 = new System.Windows.Forms.Label();
  108. this.label2 = new System.Windows.Forms.Label();
  109. this.label3 = new System.Windows.Forms.Label();
  110. this.label4 = new System.Windows.Forms.Label();
  111. this.label5 = new System.Windows.Forms.Label();
  112. this.label6 = new System.Windows.Forms.Label();
  113. this.label7 = new System.Windows.Forms.Label();
  114. this.label8 = new System.Windows.Forms.Label();
  115. this.label9 = new System.Windows.Forms.Label();
  116. this.label10 = new System.Windows.Forms.Label();
  117. this.label11 = new System.Windows.Forms.Label();
  118. this.label12 = new System.Windows.Forms.Label();
  119. this.label13 = new System.Windows.Forms.Label();
  120. this.label14 = new System.Windows.Forms.Label();
  121. this.label15 = new System.Windows.Forms.Label();
  122. this.label16 = new System.Windows.Forms.Label();
  123. this.groupBox2 = new System.Windows.Forms.GroupBox();
  124. this.listBox1 = new System.Windows.Forms.ListBox();
  125. this.groupBox1.SuspendLayout();
  126. this.groupBox2.SuspendLayout();
  127. this.SuspendLayout();
  128. // 
  129. // groupBox1
  130. // 
  131. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  132. this.label16,
  133. this.label15,
  134. this.label14,
  135. this.label13,
  136. this.label12,
  137. this.label11,
  138. this.label10,
  139. this.label9,
  140. this.label8,
  141. this.label7,
  142. this.label6,
  143. this.label5,
  144. this.label4,
  145. this.label3,
  146. this.label2,
  147. this.label1});
  148. this.groupBox1.Location = new System.Drawing.Point(16, 8);
  149. this.groupBox1.Name = "groupBox1";
  150. this.groupBox1.Size = new System.Drawing.Size(248, 288);
  151. this.groupBox1.TabIndex = 0;
  152. this.groupBox1.TabStop = false;
  153. this.groupBox1.Text = "系统信息";
  154. // 
  155. // label1
  156. // 
  157. this.label1.BackColor = System.Drawing.SystemColors.ControlLightLight;
  158. this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  159. this.label1.Location = new System.Drawing.Point(128, 32);
  160. this.label1.Name = "label1";
  161. this.label1.Size = new System.Drawing.Size(100, 16);
  162. this.label1.TabIndex = 0;
  163. // 
  164. // label2
  165. // 
  166. this.label2.BackColor = System.Drawing.SystemColors.ControlLightLight;
  167. this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  168. this.label2.Location = new System.Drawing.Point(128, 56);
  169. this.label2.Name = "label2";
  170. this.label2.Size = new System.Drawing.Size(100, 16);
  171. this.label2.TabIndex = 1;
  172. // 
  173. // label3
  174. // 
  175. this.label3.BackColor = System.Drawing.SystemColors.ControlLightLight;
  176. this.label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  177. this.label3.Location = new System.Drawing.Point(128, 88);
  178. this.label3.Name = "label3";
  179. this.label3.Size = new System.Drawing.Size(100, 16);
  180. this.label3.TabIndex = 2;
  181. // 
  182. // label4
  183. // 
  184. this.label4.BackColor = System.Drawing.SystemColors.ControlLightLight;
  185. this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  186. this.label4.Location = new System.Drawing.Point(128, 120);
  187. this.label4.Name = "label4";
  188. this.label4.Size = new System.Drawing.Size(100, 16);
  189. this.label4.TabIndex = 3;
  190. // 
  191. // label5
  192. // 
  193. this.label5.BackColor = System.Drawing.SystemColors.ControlLightLight;
  194. this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  195. this.label5.Location = new System.Drawing.Point(128, 152);
  196. this.label5.Name = "label5";
  197. this.label5.Size = new System.Drawing.Size(100, 16);
  198. this.label5.TabIndex = 4;
  199. // 
  200. // label6
  201. // 
  202. this.label6.BackColor = System.Drawing.SystemColors.ControlLightLight;
  203. this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  204. this.label6.Location = new System.Drawing.Point(128, 184);
  205. this.label6.Name = "label6";
  206. this.label6.Size = new System.Drawing.Size(100, 16);
  207. this.label6.TabIndex = 5;
  208. // 
  209. // label7
  210. // 
  211. this.label7.Location = new System.Drawing.Point(16, 32);
  212. this.label7.Name = "label7";
  213. this.label7.Size = new System.Drawing.Size(88, 16);
  214. this.label7.TabIndex = 6;
  215. this.label7.Text = "计算机名";
  216. // 
  217. // label8
  218. // 
  219. this.label8.Location = new System.Drawing.Point(16, 56);
  220. this.label8.Name = "label8";
  221. this.label8.Size = new System.Drawing.Size(88, 16);
  222. this.label8.TabIndex = 7;
  223. this.label8.Text = "用户名";
  224. // 
  225. // label9
  226. // 
  227. this.label9.Location = new System.Drawing.Point(16, 88);
  228. this.label9.Name = "label9";
  229. this.label9.Size = new System.Drawing.Size(88, 16);
  230. this.label9.TabIndex = 8;
  231. this.label9.Text = "用户域名称";
  232. // 
  233. // label10
  234. // 
  235. this.label10.Location = new System.Drawing.Point(16, 120);
  236. this.label10.Name = "label10";
  237. this.label10.Size = new System.Drawing.Size(88, 16);
  238. this.label10.TabIndex = 9;
  239. this.label10.Text = "显示器分辨率";
  240. // 
  241. // label11
  242. // 
  243. this.label11.Location = new System.Drawing.Point(16, 152);
  244. this.label11.Name = "label11";
  245. this.label11.Size = new System.Drawing.Size(88, 16);
  246. this.label11.TabIndex = 10;
  247. this.label11.Text = "网络连接";
  248. // 
  249. // label12
  250. // 
  251. this.label12.Location = new System.Drawing.Point(16, 184);
  252. this.label12.Name = "label12";
  253. this.label12.Size = new System.Drawing.Size(88, 16);
  254. this.label12.TabIndex = 11;
  255. this.label12.Text = "启动方式";
  256. // 
  257. // label13
  258. // 
  259. this.label13.BackColor = System.Drawing.SystemColors.ControlLightLight;
  260. this.label13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  261. this.label13.Location = new System.Drawing.Point(128, 216);
  262. this.label13.Name = "label13";
  263. this.label13.Size = new System.Drawing.Size(100, 16);
  264. this.label13.TabIndex = 12;
  265. // 
  266. // label14
  267. // 
  268. this.label14.BackColor = System.Drawing.SystemColors.ControlLightLight;
  269. this.label14.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  270. this.label14.Location = new System.Drawing.Point(128, 248);
  271. this.label14.Name = "label14";
  272. this.label14.Size = new System.Drawing.Size(100, 16);
  273. this.label14.TabIndex = 13;
  274. // 
  275. // label15
  276. // 
  277. this.label15.Location = new System.Drawing.Point(16, 216);
  278. this.label15.Name = "label15";
  279. this.label15.Size = new System.Drawing.Size(88, 16);
  280. this.label15.TabIndex = 14;
  281. this.label15.Text = "操作系统";
  282. // 
  283. // label16
  284. // 
  285. this.label16.Location = new System.Drawing.Point(16, 248);
  286. this.label16.Name = "label16";
  287. this.label16.Size = new System.Drawing.Size(88, 16);
  288. this.label16.TabIndex = 15;
  289. this.label16.Text = "系统版本";
  290. // 
  291. // groupBox2
  292. // 
  293. this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
  294. this.listBox1});
  295. this.groupBox2.Location = new System.Drawing.Point(280, 8);
  296. this.groupBox2.Name = "groupBox2";
  297. this.groupBox2.Size = new System.Drawing.Size(240, 288);
  298. this.groupBox2.TabIndex = 1;
  299. this.groupBox2.TabStop = false;
  300. this.groupBox2.Text = "系统服务";
  301. // 
  302. // listBox1
  303. // 
  304. this.listBox1.ItemHeight = 12;
  305. this.listBox1.Location = new System.Drawing.Point(16, 24);
  306. this.listBox1.Name = "listBox1";
  307. this.listBox1.Size = new System.Drawing.Size(208, 244);
  308. this.listBox1.Sorted = true;
  309. this.listBox1.TabIndex = 0;
  310. // 
  311. // Form1
  312. // 
  313. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  314. this.ClientSize = new System.Drawing.Size(536, 309);
  315. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  316.   this.groupBox2,
  317.   this.groupBox1});
  318. this.Name = "Form1";
  319. this.Text = "获取系统信息";
  320. this.groupBox1.ResumeLayout(false);
  321. this.groupBox2.ResumeLayout(false);
  322. this.ResumeLayout(false);
  323. }
  324. #endregion
  325. /// <summary>
  326. /// 应用程序的主入口点。
  327. /// </summary>
  328. [STAThread]
  329. static void Main() 
  330. {
  331. Application.Run(new Form1());
  332. }
  333. }
  334. }