我正在尝试用我所有的 dvd/cd 驱动器以 Windows 形式填充一个组合框,并说它们是否有光盘。
我正在尝试使用一个尝试发送对象和列表的类来做到这一点,但是该对象只是出现了错误,而列表只是出现了集合。
using System;
using System.Windows.Forms;
namespace DVD_main
{
public frmMain()
{
InitializeComponent();
cboDrive.Items.AddRange(Cls_DVD_Player.DVDDrvCtrls.cdDrv);
}
}
using System;
using System.Collections.Generic;
using System.Windows;
using System.IO;
using System.Runtime.InteropServices;
namespace Cls_DVD_Controls
{
class DVDDrvCtrls
{
private static readonly object cboDrive;
public static List<string> cdDrv()
{
List<string> drvNames = new List<string>();
DriveInfo[] cdDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in cdDrives)
{
if (d.DriveType == DriveType.CDRom && d.IsReady)
{
drvNames.Add(d.Name + " " + d.VolumeLabel);
MessageBox.Show(d.Name + " " + d.VolumeLabel);
}
else if (d.DriveType == DriveType.CDRom) {
drvNames.Add(d.Name + " Drive Empty");
}
}
//drvNames.AsReadOnly.cdDrives;
return drvNames;
}
}
}