实现效果:
知识运用:
Environment类的GetEnvironmentVariables方法
public static IDictionary GetEnvironmentVariables() //从当前进程检索所有环境变量名及其值
DictionaryEntry结构 //定义了可设置或检索的字典键/值对
Key 获取或设置键/值对中的键 Value 获取或设置键/值对中的值
实现代码:
private void Form1_Load(object sender, EventArgs e) { listView1.View = View.Details; listView1.GridLines = true; listView1.Columns.Add("环境变量",215,HorizontalAlignment.Left); listView1.Columns.Add("变量值", 215, HorizontalAlignment.Left); ListViewItem LVitem; foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables()) { LVitem = new ListViewItem(entry.Key.ToString()); LVitem.SubItems.Add(entry.Value.ToString()); listView1.Items.Add(LVitem); } }