驱动器组合框设备尚未就绪? [英] Drive Combobox Device Not Ready?

查看:75
本文介绍了驱动器组合框设备尚未就绪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在尝试以IconImage,VolumeName,VolumeLabel的格式显示组合框驱动器(示例)(图像LocalDisk C:\)

到目前为止,这是代码(更改后:IsReady和Try-Catch-End Try代码块):

I am still trying to display my combobox drive in the format of IconImage,VolumeName,VolumeLabel (Example) (Image LocalDisk C:\)

This is the code so far (with changes: IsReady and Try-Catch-End Try code block):

Imports System.IO
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Windows.Forms.Form
Imports System

Public Class Form1
    Public Sub New()
        Call InitializeComponent()
        Try
            If LicenseManager.UsageMode <> LicenseUsageMode.Designtime Then
                For Each d As DriveInfo In DriveInfo.GetDrives()
                    If d.IsReady Then                    
                        ComboBox1.Items.Add(d.Name &  d.VolumeLabel) 'never use + to join strings!
                    Else
                        ComboBox1.Items.Add(d.Name)
                    End If
                Next d
                ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
                ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        End If
        Catch ex As IO.IOException
            'MsgBox (ex.Message, MsgBoxStyle.Exclamation,"IOException")
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0
    End Sub

    Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        If e.Index = -1 Then
            Return
        End If
        Dim drive As DriveInfo = CType(ComboBox1.Items(e.Index), DriveInfo)
        Dim icon As Icon
        Select Case drive.DriveType
            Case (DriveType.Fixed)
                icon = ShellIcons.HardDisk
            Case (DriveType.CDRom)
                icon = ShellIcons.CDROM
            Case (DriveType.Network)
                icon = ShellIcons.NetDisk
            Case (DriveType.Removable)
                icon = ShellIcons.FloppyDisk
            Case Else
                icon = ShellIcons.UnknownDisk
        End Select
        Dim iconbox As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height)
        e.DrawBackground()
        e.Graphics.DrawIcon(icon, iconbox)
        icon.Dispose()
        Dim text As String = drive.Name
        If drive.IsReady Then
            If drive.VolumeLabel <> "" Then
                text = text & " (" & drive.VolumeLabel & ")"
            End If
        End If
        e.Graphics.DrawString(text, e.Font, New SolidBrush(e.ForeColor), e.Bounds.X + iconbox.Width + 1, e.Bounds.Y)
        If e.State = DrawItemState.Focus Then
            e.DrawFocusRectangle()
        End If
    End Sub
End Class



我觉得这段代码是我最近的代码,因为当我尝试调试它时,它给出了设备未准备好的错误,我将代码放在try catch语句C:\和D:\中后怀疑是CDROM.显示但不显示CDROM,仅显示驱动器号.有人可以告诉我该代码在哪里错误吗?

谢谢!



I feel that this code is the closest I have come because when I try to debug it gives the error that the device is not ready which I suspect is the CDROM after placing the code in a try catch statement the C:\ And D:\ show but not CDROM and only the drive letters. Can Someone tell me where this code is wrong?

Thank you!

推荐答案

您需要捕获错误:设备未准备好".使用Try.. Catch... Finally... End Try代码块.
尝试...捕获...最后声明 [ ^ ]
http://support.microsoft.com/kb/301283 [呆在家里学习一下
尝试…捕获VB .NET
[ ^ ]
You need to catch error: "Device not ready". Use Try.. Catch... Finally... End Try code block.
Try...Catch...Finally Statements[^]
http://support.microsoft.com/kb/301283[^]
Stay at Home and Learn
Try … Catch in VB .NET
[^]


这篇关于驱动器组合框设备尚未就绪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆