欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)獲取運行平臺系統(tǒng)信息的方法

 更新時間:2014年07月29日 09:53:11   投稿:shichen2014  
這篇文章主要介紹了C#實現(xiàn)獲取運行平臺系統(tǒng)信息的方法,比較典型的C#應(yīng)用,需要的朋友可以參考下

本文實例講述了C#獲取運行平臺系統(tǒng)信息的方法,主要可以實現(xiàn)C#獲取系統(tǒng)啟動經(jīng)過的毫秒數(shù),相連網(wǎng)絡(luò)域名,系統(tǒng)啟動經(jīng)過的毫秒數(shù)等,并有關(guān)于ListView控件的相關(guān)操作。

具體的實現(xiàn)代碼如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 獲取系統(tǒng)環(huán)境和平臺信息
{
 public class Form1 : System.Windows.Forms.Form
 {
 private System.Windows.Forms.Button button1;
 private System.Windows.Forms.Button button2;
 private System.Windows.Forms.ListView listView1;
 private System.Windows.Forms.ColumnHeader columnHeader1;
 private System.Windows.Forms.ColumnHeader columnHeader2;
 private System.ComponentModel.Container components = null;
 public Form1()
 {
  InitializeComponent();
 }
 protected override void Dispose( bool disposing )
 {
  if( disposing )
  {
  if (components != null)
  {
   components.Dispose();
  }
  }
  base.Dispose( disposing );
 }
 #region Windows 窗體設(shè)計器生成的代碼
 private void InitializeComponent()
 {
  this.button1 = new System.Windows.Forms.Button();
  this.button2 = new System.Windows.Forms.Button();
  this.listView1 = new System.Windows.Forms.ListView();
  this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
  this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
  this.SuspendLayout();
  // button1
  this.button1.Location = new System.Drawing.Point(48, 224);
  this.button1.Name = "button1";
  this.button1.Size = new System.Drawing.Size(56, 32);
  this.button1.TabIndex = 4;
  this.button1.Text = "獲取";
  this.button1.Click += new System.EventHandler(this.button1_Click);
  // button2
  this.button2.Location = new System.Drawing.Point(184, 224);
  this.button2.Name = "button2";
  this.button2.Size = new System.Drawing.Size(56, 32);
  this.button2.TabIndex = 5;
  this.button2.Text = "退出";
  this.button2.Click += new System.EventHandler(this.button2_Click);
  //
  // listView1
  this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
           this.columnHeader1,
           this.columnHeader2});
  this.listView1.GridLines = true;
  this.listView1.Location = new System.Drawing.Point(16, 24);
  this.listView1.Name = "listView1";
  this.listView1.Size = new System.Drawing.Size(256, 184);
  this.listView1.TabIndex = 6;
  this.listView1.View = System.Windows.Forms.View.Details;
  // columnHeader1
  this.columnHeader1.Text = "屬性";
  this.columnHeader1.Width = 100;
  // columnHeader2
  this.columnHeader2.Text = "值";
  this.columnHeader2.Width = 175;
  // Form1
  this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  this.ClientSize = new System.Drawing.Size(292, 273);
  this.Controls.Add(this.listView1);
  this.Controls.Add(this.button2);
  this.Controls.Add(this.button1);
  this.Name = "Form1";
  this.Text = "獲取系統(tǒng)環(huán)境和平臺信息";
  this.ResumeLayout(false);
 }
 #endregion
 [STAThread]
 static void Main()
 {
  Application.Run(new Form1());
 }
 private void button2_Click(object sender, System.EventArgs e)
 {
  // 關(guān)閉當(dāng)前窗體
  this.Close();
 }
 private void button1_Click(object sender, System.EventArgs e)
 {
  listView1.Items.Clear(); // 清除ListView控件中的項
  ListViewItem listViewItem;
  try
  {
  // 加入計算機名
  listViewItem = new ListViewItem("計算機名", 0);
  listViewItem.SubItems.Add(Environment.MachineName);
  listView1.Items.Add(listViewItem);
  // 加入當(dāng)前平臺名
  listViewItem = new ListViewItem("當(dāng)前平臺名", 0);
  listViewItem.SubItems.Add(Environment.OSVersion.Platform.ToString());
  listView1.Items.Add(listViewItem);
  // 加入平臺版本號
  listViewItem = new ListViewItem("平臺版本號", 0);
  listViewItem.SubItems.Add(Environment.OSVersion.Version.ToString());
  listView1.Items.Add(listViewItem);
  // 與系統(tǒng)相連的網(wǎng)絡(luò)名
  listViewItem = new ListViewItem("相連網(wǎng)絡(luò)域名", 0);
  listViewItem.SubItems.Add(Environment.UserDomainName);
  listView1.Items.Add(listViewItem);
  // 系統(tǒng)目錄路徑
  listViewItem = new ListViewItem("系統(tǒng)啟動經(jīng)過的毫秒數(shù)", 0);
  listViewItem.SubItems.Add(Environment.SystemDirectory );
  listView1.Items.Add(listViewItem);
  // 系統(tǒng)當(dāng)前時間
  listViewItem = new ListViewItem("系統(tǒng)當(dāng)前時間", 0);
  listViewItem.SubItems.Add(DateTime.Now.ToString());
  listView1.Items.Add(listViewItem);
  // 系統(tǒng)啟動后經(jīng)過的毫秒數(shù)
  listViewItem = new ListViewItem("系統(tǒng)啟動經(jīng)過的毫秒數(shù)", 0);
  listViewItem.SubItems.Add(Environment.TickCount.ToString());
  listView1.Items.Add(listViewItem);
  }
  catch(Exception exc)
  {
  MessageBox.Show(exc.Message, "提示");
  }
 }
 // 為避免編寫的代碼冗長,添加 AddItem 方法
 public void AddItem(string sItem)
 {
  // 添加項 sItem 到 listView1 中
  listView1.Items.Add(sItem);
 }
 }
}

相關(guān)文章

  • c# 接口使用實例

    c# 接口使用實例

    這篇文章主要介紹了c#接口使用的實例,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • C#實現(xiàn)Socket服務(wù)器及多客戶端連接的方式

    C#實現(xiàn)Socket服務(wù)器及多客戶端連接的方式

    這篇文章介紹了C#實現(xiàn)Socket服務(wù)器及多客戶端連接的方式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • C#動態(tài)生成PictureBox并指定圖片的方法

    C#動態(tài)生成PictureBox并指定圖片的方法

    這篇文章主要介紹了C#動態(tài)生成PictureBox并指定圖片的方法,實例分析了C#圖形控件的動態(tài)生成及使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • C# 內(nèi)部類與Lambda表達式用法詳解

    C# 內(nèi)部類與Lambda表達式用法詳解

    Lambda表達式是一個匿名函數(shù),Lambda表達式基于數(shù)學(xué)中的λ演算得名,直接對應(yīng)于其中的lambda抽象,是一個匿名函數(shù),即沒有函數(shù)名的函數(shù);內(nèi)部類是將一個類定義在另一個給類里面或者方法里面,這樣的類就被稱為內(nèi)部類
    2021-10-10
  • C#使用泛型方法設(shè)計實現(xiàn)單向鏈表詳解

    C#使用泛型方法設(shè)計實現(xiàn)單向鏈表詳解

    這篇文章主要為大家詳細(xì)介紹了C#如何使用泛型方法設(shè)計實現(xiàn)一個單向鏈表,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • asp.net(C#)清除全部Session與單個Session的方法

    asp.net(C#)清除全部Session與單個Session的方法

    下面小編就為大家?guī)硪黄猘sp.net(C#)清除全部Session與單個Session的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • C#序列化與反序列化實例

    C#序列化與反序列化實例

    這篇文章主要介紹了C#序列化與反序列化的實現(xiàn)方法,實例分析了序列化與反序列化的原理與實現(xiàn)技巧,需要的朋友可以參考下
    2015-01-01
  • C# 如何調(diào)用SAP RFC

    C# 如何調(diào)用SAP RFC

    這篇文章主要介紹了C# 如何調(diào)用SAP RFC,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#實現(xiàn)HSL顏色值轉(zhuǎn)換為RGB的方法

    C#實現(xiàn)HSL顏色值轉(zhuǎn)換為RGB的方法

    這篇文章主要介紹了C#實現(xiàn)HSL顏色值轉(zhuǎn)換為RGB的方法,涉及C#數(shù)值判定與轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06

最新評論