Imports System.IO Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.Windows.Forms.Form Imports System Public Class Form1 Public Function ListAllDrives() As String() Dim arDrives() As String arDrives = Directory.GetLogicalDrives() Return arDrives End Function Public Sub New() Call InitializeComponent() If LicenseManager.UsageMode <> LicenseUsageMode.Designtime Then For Each drive_info As DriveInfo In DriveInfo.GetDrives() ComboBox1.Items.Add(drive_info.Name & " ") ComboBox1.Items.Add(drive_info.RootDirectory.ToString) If drive_info.IsReady() Then ComboBox1.Items.Add(drive_info.VolumeLabel()) End If Next drive_info ComboBox1.DrawMode = DrawMode.OwnerDrawFixed ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList End If 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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)