Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 6k
Category:

ADO-ODBC

Development Platform:

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 Microsoft.Win32;
  8. namespace ch4_3
  9. {
  10. /// <summary>
  11. /// Form1 的摘要说明。
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.GroupBox groupBox1;
  16. private System.Windows.Forms.Label label1;
  17. private System.Windows.Forms.Label label2;
  18. private System.Windows.Forms.Label label3;
  19. private System.Windows.Forms.Label label4;
  20. private System.Windows.Forms.Label label5;
  21. private System.Windows.Forms.Label label6;
  22. private System.Windows.Forms.Label label7;
  23. private System.Windows.Forms.Label label8;
  24. /// <summary>
  25. /// 必需的设计器变量。
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public Form1()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34.     
  35. GetCpuInfo();
  36. //
  37. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  38. //
  39. }
  40. private void GetCpuInfo()
  41. {
  42. //获得代表CPU信息的节点
  43. RegistryKey  hLocalMachine=Registry.LocalMachine;
  44. RegistryKey  hardware=hLocalMachine.OpenSubKey("HARDWARE");
  45. RegistryKey  description=hardware.OpenSubKey("DESCRIPTION");
  46. RegistryKey  system=description.OpenSubKey("SYSTEM");
  47. RegistryKey  processor=system.OpenSubKey("CentralProcessor");
  48. RegistryKey  information=processor.OpenSubKey("0");
  49.     //获取主键中指定键的键值,并写入相应的Label控件
  50. this.label5.Text=information.GetValue("VendorIdentifier").ToString();
  51.     this.label6.Text=information.GetValue("ProcessorNameString").ToString();
  52.     this.label7.Text=information.GetValue("Identifier").ToString();
  53. this.label8.Text=information.GetValue("~MHz").ToString()+" MHz";
  54. }
  55. /// <summary>
  56. /// 清理所有正在使用的资源。
  57. /// </summary>
  58. protected override void Dispose( bool disposing )
  59. {
  60. if( disposing )
  61. {
  62. if (components != null) 
  63. {
  64. components.Dispose();
  65. }
  66. }
  67. base.Dispose( disposing );
  68. }
  69. #region Windows Form Designer generated code
  70. /// <summary>
  71. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  72. /// 此方法的内容。
  73. /// </summary>
  74. private void InitializeComponent()
  75. {
  76. this.groupBox1 = new System.Windows.Forms.GroupBox();
  77. this.label8 = new System.Windows.Forms.Label();
  78. this.label7 = new System.Windows.Forms.Label();
  79. this.label6 = new System.Windows.Forms.Label();
  80. this.label5 = new System.Windows.Forms.Label();
  81. this.label4 = new System.Windows.Forms.Label();
  82. this.label3 = new System.Windows.Forms.Label();
  83. this.label2 = new System.Windows.Forms.Label();
  84. this.label1 = new System.Windows.Forms.Label();
  85. this.groupBox1.SuspendLayout();
  86. this.SuspendLayout();
  87. // 
  88. // groupBox1
  89. // 
  90. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  91. this.label8,
  92. this.label7,
  93. this.label6,
  94. this.label5,
  95. this.label4,
  96. this.label3,
  97. this.label2,
  98. this.label1});
  99. this.groupBox1.Location = new System.Drawing.Point(16, 16);
  100. this.groupBox1.Name = "groupBox1";
  101. this.groupBox1.Size = new System.Drawing.Size(344, 176);
  102. this.groupBox1.TabIndex = 0;
  103. this.groupBox1.TabStop = false;
  104. this.groupBox1.Text = "cpu 信息";
  105. // 
  106. // label8
  107. // 
  108. this.label8.BackColor = System.Drawing.SystemColors.ControlLightLight;
  109. this.label8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  110. this.label8.Location = new System.Drawing.Point(112, 128);
  111. this.label8.Name = "label8";
  112. this.label8.Size = new System.Drawing.Size(192, 16);
  113. this.label8.TabIndex = 7;
  114. // 
  115. // label7
  116. // 
  117. this.label7.BackColor = System.Drawing.SystemColors.ControlLightLight;
  118. this.label7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  119. this.label7.Location = new System.Drawing.Point(112, 96);
  120. this.label7.Name = "label7";
  121. this.label7.Size = new System.Drawing.Size(192, 16);
  122. this.label7.TabIndex = 6;
  123. // 
  124. // label6
  125. // 
  126. this.label6.BackColor = System.Drawing.SystemColors.ControlLightLight;
  127. this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  128. this.label6.Location = new System.Drawing.Point(112, 64);
  129. this.label6.Name = "label6";
  130. this.label6.Size = new System.Drawing.Size(192, 16);
  131. this.label6.TabIndex = 5;
  132. // 
  133. // label5
  134. // 
  135. this.label5.BackColor = System.Drawing.SystemColors.ControlLightLight;
  136. this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  137. this.label5.Location = new System.Drawing.Point(112, 32);
  138. this.label5.Name = "label5";
  139. this.label5.Size = new System.Drawing.Size(192, 16);
  140. this.label5.TabIndex = 4;
  141. // 
  142. // label4
  143. // 
  144. this.label4.Location = new System.Drawing.Point(24, 128);
  145. this.label4.Name = "label4";
  146. this.label4.Size = new System.Drawing.Size(64, 16);
  147. this.label4.TabIndex = 3;
  148. this.label4.Text = "速度";
  149. // 
  150. // label3
  151. // 
  152. this.label3.Location = new System.Drawing.Point(24, 96);
  153. this.label3.Name = "label3";
  154. this.label3.Size = new System.Drawing.Size(64, 16);
  155. this.label3.TabIndex = 2;
  156. this.label3.Text = "标识";
  157. // 
  158. // label2
  159. // 
  160. this.label2.Location = new System.Drawing.Point(24, 64);
  161. this.label2.Name = "label2";
  162. this.label2.Size = new System.Drawing.Size(64, 16);
  163. this.label2.TabIndex = 1;
  164. this.label2.Text = "描述";
  165. // 
  166. // label1
  167. // 
  168. this.label1.Location = new System.Drawing.Point(24, 32);
  169. this.label1.Name = "label1";
  170. this.label1.Size = new System.Drawing.Size(64, 16);
  171. this.label1.TabIndex = 0;
  172. this.label1.Text = "制造商";
  173. // 
  174. // Form1
  175. // 
  176. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  177. this.ClientSize = new System.Drawing.Size(376, 221);
  178. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  179.   this.groupBox1});
  180. this.Name = "Form1";
  181. this.Text = "cpu信息";
  182. this.groupBox1.ResumeLayout(false);
  183. this.ResumeLayout(false);
  184. }
  185. #endregion
  186. /// <summary>
  187. /// 应用程序的主入口点。
  188. /// </summary>
  189. [STAThread]
  190. static void Main() 
  191. {
  192. Application.Run(new Form1());
  193. }
  194. }
  195. }