C#實(shí)現(xiàn)獲取運(yùn)行平臺(tái)系統(tǒng)信息的方法
本文實(shí)例講述了C#獲取運(yùn)行平臺(tái)系統(tǒng)信息的方法,主要可以實(shí)現(xiàn)C#獲取系統(tǒng)啟動(dòng)經(jīng)過(guò)的毫秒數(shù),相連網(wǎng)絡(luò)域名,系統(tǒng)啟動(dòng)經(jīng)過(guò)的毫秒數(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)境和平臺(tái)信息
{
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)境和平臺(tái)信息";
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)前平臺(tái)名
listViewItem = new ListViewItem("當(dāng)前平臺(tái)名", 0);
listViewItem.SubItems.Add(Environment.OSVersion.Platform.ToString());
listView1.Items.Add(listViewItem);
// 加入平臺(tái)版本號(hào)
listViewItem = new ListViewItem("平臺(tái)版本號(hào)", 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)過(guò)的毫秒數(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)過(guò)的毫秒數(shù)
listViewItem = new ListViewItem("系統(tǒng)啟動(dòng)經(jīng)過(guò)的毫秒數(shù)", 0);
listViewItem.SubItems.Add(Environment.TickCount.ToString());
listView1.Items.Add(listViewItem);
}
catch(Exception exc)
{
MessageBox.Show(exc.Message, "提示");
}
}
// 為避免編寫(xiě)的代碼冗長(zhǎng),添加 AddItem 方法
public void AddItem(string sItem)
{
// 添加項(xiàng) sItem 到 listView1 中
listView1.Items.Add(sItem);
}
}
}
- C#實(shí)現(xiàn)的Socket服務(wù)器端、客戶(hù)端代碼分享
- 在C#中對(duì)TCP客戶(hù)端的狀態(tài)封裝詳解
- C#用Activex實(shí)現(xiàn)Web客戶(hù)端讀取RFID功能的代碼
- c# socket編程udp客戶(hù)端實(shí)現(xiàn)代碼分享
- 獲取客戶(hù)端IP地址c#/vb.net各自實(shí)現(xiàn)代碼
- 分享用于操作FTP的客戶(hù)端C#類(lèi)
- C#如何取硬件標(biāo)志
- 使用C#配合ArcGIS Engine進(jìn)行地理信息系統(tǒng)開(kāi)發(fā)
- C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解
- 使用C#獲取系統(tǒng)特殊文件夾路徑的解決方法
- C#獲取系統(tǒng)版本信息方法
- C# 獲取系統(tǒng)進(jìn)程的用戶(hù)名
- C#編程獲取客戶(hù)端計(jì)算機(jī)硬件及系統(tǒng)信息功能示例
相關(guān)文章
c#實(shí)現(xiàn)數(shù)據(jù)同步的方法(使用文件監(jiān)控對(duì)象filesystemwatcher)
這篇文章主要介紹了C#使用文件監(jiān)控對(duì)象FileSystemWatcher實(shí)現(xiàn)數(shù)據(jù)同步,大家參考使用吧2013-12-12
C#發(fā)送HttpPost請(qǐng)求來(lái)調(diào)用WebService的方法
在C#中發(fā)送HttpPost請(qǐng)求來(lái)調(diào)用WebService中的MyAction方法,代碼如下:需要的朋友可以參考一下2013-03-03
基于C#實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放器
這篇文章主要介紹了如何基于C#實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放器,考慮到需求中的界面友好和跨版本兼容性,我們可以選擇選擇Windows Forms作為開(kāi)發(fā)平臺(tái),Windows Forms提供了一個(gè)簡(jiǎn)單而強(qiáng)大的方法來(lái)創(chuàng)建桌面應(yīng)用程序,文中通過(guò)代碼示例給大家講解的非常詳細(xì),需要的朋友可以參考下2024-05-05
C#并發(fā)編程之a(chǎn)sync和await關(guān)鍵字詳解
對(duì)于?async?和?await?兩個(gè)關(guān)鍵字,對(duì)于一線開(kāi)發(fā)人員再熟悉不過(guò)了,到處都是它們的身影,下面小編就來(lái)和大家記錄匯總下它們的使用吧2023-07-07
C#程序中session值的保存方法以及轉(zhuǎn)為字符串的方法總結(jié)
這篇文章主要介紹了C#程序中session值的保存方法以及轉(zhuǎn)為字符串的方法總結(jié),經(jīng)常被用于ASP.NET網(wǎng)絡(luò)編程項(xiàng)目中,需要的朋友可以參考下2016-04-04
C# Csv實(shí)現(xiàn)基本的讀寫(xiě)和轉(zhuǎn)換DataTable
本文主要介紹了C# Csv實(shí)現(xiàn)基本的讀寫(xiě)和轉(zhuǎn)換DataTable,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
WPF實(shí)現(xiàn)動(dòng)畫(huà)效果(四)之緩動(dòng)函數(shù)
這篇文章介紹了WPF實(shí)現(xiàn)動(dòng)畫(huà)效果之緩動(dòng)函數(shù),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06

