簡體   English   中英

嘗試讀取 dvd/cd 驅動器並在 C# 中填充組合框

[英]trying to read dvd/cd drives and populate combo box in c#

我試圖用我所有的 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;

        }
    }
}

/*this was the best i could do couldn't find way for the class to pass the details i wanted this was the best i could find*/    

private void CheckDrive()
    {
        //string[] dvdDrives = new Cls_DVD_Player.DVDDrvCtrls();

        //List<string> drvNames = new List<string>();
        DriveInfo[] cdDrives = DriveInfo.GetDrives();
        cboDrive.Items.Clear();

        foreach (DriveInfo d in cdDrives)
        {
            if (d.DriveType == DriveType.CDRom && d.IsReady)
            {
                cboDrive.Items.Add(d.Name + " " + d.VolumeLabel);
                //MessageBox.Show(d.Name + " " + d.VolumeLabel);
            }
            else if (d.DriveType == DriveType.CDRom)
            {
                cboDrive.Items.Add(d.Name + " Drive Empty");
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM