在组合框中列出驱动器名称? [英] List Drive Name In Combobox?
本文介绍了在组合框中列出驱动器名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,最后一次尝试是请有人添加或告诉我要更改的内容,以便我的驱动器组合框显示以下格式:
图标LocalDisk C:\
图标SecondDrive D:\
图标CD E:\
我已经提交了到目前为止的代码:
Ok as one last attempt will someone please add or tell me what to change so that my drive combobox will display the format:
Icon LocalDisk C:\
Icon SecondDrive D:\
Icon CDROM E:\
I have submitted the code I have so far:
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
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
推荐答案
Dale,
看起来以前已经做过了;
快速驱动器组合框 [
Dale,
Looks like this has been done before;
Fast Drive ComboBox[^]
Maybe worth reading that and tweeking to fit your needs (if at all!). :)
There are also a few other articles referenced within this one.
看看上一个问题中的解决方案2: ^ ],专门在VB.NET中的ImageCombobox [ ^ ]
Take a look at solution 2 in your previous question: How To Display Drive Type In Combobox?[^], a specially at ImageCombobox in VB.NET[^]
这篇关于在组合框中列出驱动器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文