//选中磁盘驱动器信息再RichBox控件和DataGridview控件中 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;namespace TestDriveInfo...{ public partial class Form1 : Form ...{ public partial class frmStatus : Form ...{ public void Show(string Message) ...{ Application.DoEvents(); } } public Form1() ...{ InitializeComponent(); } private void button1_Click(object sender, EventArgs e) ...{ //显示一个状态信息框来表示目前要尝试取得计算机的磁盘信息 frmStatus frmStatusMessage = new frmStatus(); frmStatusMessage.Show(“处理中,请稍后.......”); StringBuilder sb = new StringBuilder();//可变字符串 DriveInfo[] myAllDrives = DriveInfo.GetDrives(); try ...{ foreach (DriveInfo myDrive in myAllDrives) ...{ //使用IsReady属性判断磁盘设备是否就绪 if (myDrive.IsReady) ...{ sb.Append("磁盘驱动器符:"); sb.AppendLine(myDrive.Name); sb.Append("磁盘卷符:"); sb.AppendLine(myDrive.VolumeLabel); sb.Append("磁盘类型:"); sb.AppendLine(myDrive.DriveType.ToString()); sb.Append("磁盘的大小:"); sb.AppendLine(myDrive.TotalSize.ToString()); sb.Append("磁盘剩余空间:"); sb.AppendLine(myDrive.TotalFreeSpace.ToString()); sb.Append("总剩余空间(含磁盘配额):"); sb.AppendLine(myDrive.AvailableFreeSpace.ToString()); sb.AppendLine("---------------------------------------"); } } } catch(Exception ex) ...{ MessageBox.Show(ex.Message); } frmStatusMessage.Close(); this.richTextBox1.Text = sb.ToString(); //显示于DataGridView控件中 //this.dataGridView1.DataError+=new DataGridViewDataErrorEventHandler(dataGridView1_DataError); this.dataGridView1.DataSource = DriveInfo.GetDrives(); } private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e) ...{ } private void Form1_Load(object sender, EventArgs e) ...{ DriveInfo[] myAllDriveInfo = DriveInfo.GetDrives(); this.comboBox1.Items.AddRange(myAllDriveInfo); } //combox控件选中事件 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) ...{ DriveInfo theDriveInfo=(DriveInfo)comboBox1.Items[comboBox1.SelectedIndex]; if (theDriveInfo.IsReady) ...{ this.propertyGrid1.SelectedObject = comboBox1.Items[comboBox1.SelectedIndex]; } else ...{ MessageBox.Show(theDriveInfo.Name+"磁盘尚未就绪","请注意",MessageBoxButtons.OK); this.propertyGrid1.SelectedObject = null; } } }}