如何通过驱动器号获取VB.NET中的驱动器类型。 [英] How to get the drive type in VB.NET by drive letter.
本文介绍了如何通过驱动器号获取VB.NET中的驱动器类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个程序,用硬盘驱动器,本地磁盘,CD驱动器,sdhd,系统驱动器(c :)等驱动器号显示用户输入驱动器的类型。
我尝试过:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
dfunton(TextBox1.Text)
End Sub
Private Sub dfunton( ByVal p1 As Object)
'获取驱动器类型的代码
Label1.Text =drivetype
End Sub
End Class
解决方案
查看 DriveInfo类(System.IO) [ ^ ] - 它返回您需要的信息。
Public Class Fo rm1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
dfunton(TextBox1.Text)
End Sub
Private Sub GetDrivetype(ByVal drive As String)
尝试
Dim Drive_Info As System.IO.DriveInfo
Drive_Info = New System.IO.DriveInfo(drive)
Label1.Text = Drive_Info.DriveType.ToString
Catch ex As Exception
MsgBox(ex.Data)
End Try
End Sub
End Class
I am making a program that shows the type of the user inputted drive by drive letter like pen drive , local disk , cd drive, sdhd, system drive (c:).
What I have tried:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dfunton(TextBox1.Text) End Sub Private Sub dfunton(ByVal p1 As Object) 'code for getting drive type Label1.Text = "drivetype" End Sub End Class
解决方案
Look at the DriveInfo Class (System.IO)[^] - it returns the info you need.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dfunton(TextBox1.Text) End Sub Private Sub GetDrivetype(ByVal drive As String) Try Dim Drive_Info As System.IO.DriveInfo Drive_Info = New System.IO.DriveInfo(drive) Label1.Text = Drive_Info.DriveType.ToString Catch ex As Exception MsgBox(ex.Data) End Try End Sub End Class
这篇关于如何通过驱动器号获取VB.NET中的驱动器类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文