C#實(shí)現(xiàn)獲取運(yùn)行平臺系統(tǒng)信息的方法
本文實(shí)例講述了C#獲取運(yùn)行平臺系統(tǒng)信息的方法,主要可以實(shí)現(xiàn)C#獲取系統(tǒng)啟動(dòng)經(jīng)過的毫秒數(shù),相連網(wǎng)絡(luò)域名,系統(tǒng)啟動(dòng)經(jīng)過的毫秒數(shù)等,并有關(guān)于ListView控件的相關(guān)操作。
具體的實(shí)現(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è)計(jì)器生成的代碼 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控件中的項(xiàng) ListViewItem listViewItem; try { // 加入計(jì)算機(jī)名 listViewItem = new ListViewItem("計(jì)算機(jī)名", 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)啟動(dòng)經(jīng)過的毫秒數(shù)", 0); listViewItem.SubItems.Add(Environment.SystemDirectory ); listView1.Items.Add(listViewItem); // 系統(tǒng)當(dāng)前時(shí)間 listViewItem = new ListViewItem("系統(tǒng)當(dāng)前時(shí)間", 0); listViewItem.SubItems.Add(DateTime.Now.ToString()); listView1.Items.Add(listViewItem); // 系統(tǒng)啟動(dòng)后經(jīng)過的毫秒數(shù) listViewItem = new ListViewItem("系統(tǒng)啟動(dò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) { // 添加項(xiàng) sItem 到 listView1 中 listView1.Items.Add(sItem); } } }
- C#實(shí)現(xiàn)的Socket服務(wù)器端、客戶端代碼分享
- 在C#中對TCP客戶端的狀態(tài)封裝詳解
- C#用Activex實(shí)現(xiàn)Web客戶端讀取RFID功能的代碼
- c# socket編程udp客戶端實(shí)現(xiàn)代碼分享
- 獲取客戶端IP地址c#/vb.net各自實(shí)現(xiàn)代碼
- 分享用于操作FTP的客戶端C#類
- C#如何取硬件標(biāo)志
- 使用C#配合ArcGIS Engine進(jìn)行地理信息系統(tǒng)開發(fā)
- C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解
- 使用C#獲取系統(tǒng)特殊文件夾路徑的解決方法
- C#獲取系統(tǒng)版本信息方法
- C# 獲取系統(tǒng)進(jìn)程的用戶名
- C#編程獲取客戶端計(jì)算機(jī)硬件及系統(tǒng)信息功能示例
相關(guān)文章
C#實(shí)現(xiàn)Socket服務(wù)器及多客戶端連接的方式
這篇文章介紹了C#實(shí)現(xiàn)Socket服務(wù)器及多客戶端連接的方式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01C#動(dòng)態(tài)生成PictureBox并指定圖片的方法
這篇文章主要介紹了C#動(dòng)態(tài)生成PictureBox并指定圖片的方法,實(shí)例分析了C#圖形控件的動(dòng)態(tài)生成及使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07C#使用泛型方法設(shè)計(jì)實(shí)現(xiàn)單向鏈表詳解
這篇文章主要為大家詳細(xì)介紹了C#如何使用泛型方法設(shè)計(jì)實(shí)現(xiàn)一個(gè)單向鏈表,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02asp.net(C#)清除全部Session與單個(gè)Session的方法
下面小編就為大家?guī)硪黄猘sp.net(C#)清除全部Session與單個(gè)Session的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12C#TreeView 無限級別分類實(shí)現(xiàn)方法
2013-04-04C#實(shí)現(xiàn)HSL顏色值轉(zhuǎn)換為RGB的方法
這篇文章主要介紹了C#實(shí)現(xiàn)HSL顏色值轉(zhuǎn)換為RGB的方法,涉及C#數(shù)值判定與轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下2015-06-06