在SystemIO命名空间下的DriveInfo类的GetDrives()方法可以用来获得计算机上的所有逻辑驱动器的名称DriveInfo类的TotalSize属性可义获得磁盘的空间大小主要代码如下
privatevoidForm_Load(objectsenderEventArgse)
{
SystemIODriveInfo[]drive=SystemIODriveInfoGetDrives();
for(inti=;i<driveLength;i++)
{
comboBoxItemsAdd(drive[i]Name);
}
}
privatevoidcomboBox_SelectedValueChanged(objectsenderEventArgse)
{
SystemIODriveInfo[]drive=SystemIODriveInfoGetDrives();
for(inti=;i<driveLength;i++)
{
if(comboBoxSelectedItemToString()==drive[i]Name)
{
textBoxText=ConvertToString(drive[i]TotalSize/);
}
}
}