龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

.NET实现主机性能监控系统之获取计算机信息(3)

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
添加一个窗体,命名为:SystemInfoForm,往窗体里面添加一个ListView控件,代码如下: C# 代码 [http://www.xueit.com] public partial class SystemInfoForm : Form { public Syste

添加一个窗体,命名为:SystemInfoForm,往窗体里面添加一个ListView控件,代码如下:

C# 代码 [http://www.xueit.com]
    public partial class SystemInfoForm : Form
    {
        public SystemInfoForm()
        {
            InitializeComponent();
        }

        private void SystemInfoForm_Load(object sender, EventArgs e)
        {
            //实例化一个ComputerInfo.SystemInfo类。
            ComputerInfo.SystemInfo systemInfo = new ComputerInfo.SystemInfo();

            定义一些需要用到的项#region 定义一些需要用到的项
            ListViewItem lviOSName = new ListViewItem(new string[]{ "OS 名称",systemInfo.OSName});
            ListViewItem lviOSVersion = new ListViewItem(new string[] { "版本", systemInfo.OSVersion });
            ListViewItem lviOSManufacturer = new ListViewItem(new string[] { "OS 制造商", systemInfo.OSManufacturer });
            ListViewItem lviSystemName = new ListViewItem(new string[] { "系统名称", systemInfo.SystemName });
            ListViewItem lviWindowsDirectory = new ListViewItem(new string[] { "Windows 目录", systemInfo.WindowsDirectory });
            ListViewItem lviSystemDirectory = new ListViewItem(new string[] { "系统目录", systemInfo.SystemDirectory });
            ListViewItem lviBootDevice = new ListViewItem(new string[] { "启动设备", systemInfo.BootDevice });
            ListViewItem lviCountry = new ListViewItem(new string[] { "区域设置", systemInfo.Country });
            ListViewItem lviTimeZone = new ListViewItem(new string[] { "时区", systemInfo.TimeZone });
            ListViewItem lviTotalVisibleMemorySize = new ListViewItem(new string[] { "总的物理内存", systemInfo.TotalVisibleMemorySize });
            ListViewItem lviFreePhysicalMemory = new ListViewItem(new string[] { "可用物理内存", systemInfo.FreePhysicalMemory });
            ListViewItem lviTotalVirtualMemorySize = new ListViewItem(new string[] { "总的虚拟内存", systemInfo.TotalVirtualMemorySize });
            ListViewItem lviFreeVirtualMemory = new ListViewItem(new string[] { "可用虚拟内存", systemInfo.FreeVirtualMemory });
            ListViewItem lviSizeStoredInPagingFiles = new ListViewItem(new string[] { "页面文件空间", systemInfo.SizeStoredInPagingFiles });
            #endregion

            将项添加到ListView控件里面#region 将项添加到ListView控件里面
            lvHostInformation.Items.Add(lviOSName);
            lvHostInformation.Items.Add(lviOSVersion);
            lvHostInformation.Items.Add(lviOSManufacturer);
            lvHostInformation.Items.Add(lviSystemName);
            lvHostInformation.Items.Add(lviWindowsDirectory);
            lvHostInformation.Items.Add(lviSystemDirectory);
            lvHostInformation.Items.Add(lviBootDevice);
            lvHostInformation.Items.Add(lviCountry);
            lvHostInformation.Items.Add(lviTimeZone);
            lvHostInformation.Items.Add(lviTotalVisibleMemorySize);
            lvHostInformation.Items.Add(lviFreePhysicalMemory);
            lvHostInformation.Items.Add(lviTotalVirtualMemorySize);
            lvHostInformation.Items.Add(lviFreeVirtualMemory);
            lvHostInformation.Items.Add(lviSizeStoredInPagingFiles);
            #endregion

            设置ListView的样式以及列#region 设置ListView的样式以及列
            lvHostInformation.View = View.Details;
            lvHostInformation.Columns.Add("",150);
            lvHostInformation.Columns.Add("",300);
            lvHostInformation.FullRowSelect = true;
            lvHostInformation.GridLines = true;
            #endregion
        }
    }

至此,获取计算机信息的小功能就做完了,代码都已经贴上来了,大家可以自己弄到VS2008里面试.试


精彩图集

赞助商链接