⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 VB
字号:
Imports VB = Microsoft.VisualBasic
Friend Class Form1
    Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
    Public Sub New()
        MyBase.New()
        '此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
    End Sub
    '窗体重写处置,以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器来修改它。
    '不要使用代码编辑器修改它。
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Public WithEvents ListBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'ListBox1
        '
        Me.ListBox1.BackColor = System.Drawing.SystemColors.Window
        Me.ListBox1.Cursor = System.Windows.Forms.Cursors.Default
        Me.ListBox1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(8, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ListBox1.Size = New System.Drawing.Size(257, 136)
        Me.ListBox1.TabIndex = 1
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(72, 160)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(100, 30)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "退出"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(269, 197)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.ListBox1)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Location = New System.Drawing.Point(253, 127)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Tag = "hello"
        Me.Text = "获得驱动器的类型"
        Me.ResumeLayout(False)

    End Sub
#End Region
    '  用来返回磁盘驱动器的个数
    Public Function DriveCount() As Short
        Dim BitMask As Integer
        Dim j, i As Object

        BitMask = GetLogicalDrives()
        For i = 0 To 24
            If BitMask And 2 ^ i Then
                j = j + 1
            End If
        Next i
        DriveCount = j
    End Function

    '  返回驱动器的名称
    Public Function LoadDrivenames(ByRef An_Array() As String) As Integer
        Dim j, i As Object
        Dim lpBuffer As String

        ReDim An_Array(128)
        lpBuffer = Space(1024)
        '  返回当前所有逻辑驱动器的根驱动器路径
        GetLogicalDriveStrings(Len(lpBuffer), lpBuffer)
        j = InStr(lpBuffer, Chr(0))
        '  存储磁盘驱动器的名称到An_Array中
        Do While j > 0
            An_Array(i) = VB.Left(lpBuffer, j - 1)
            i = i + 1
            lpBuffer = Mid(lpBuffer, j + 1)
            j = InStr(lpBuffer, Chr(0))
        Loop
        ReDim Preserve An_Array(DriveCount)
    End Function

    '  返回磁盘驱动器的类型
    Public Function Types(Optional ByRef sDrive As String = "") As String
        Select Case GetDriveType(sDrive)
            Case DRIVE_UNKNOWN
                Types = "不能识别"
            Case DRIVE_NO_ROOT_DIR
                Types = "不存在"
            Case DRIVE_REMOVABLE
                Types = "可移除驱动器"
            Case DRIVE_FIXED
                Types = "固定驱动器"
            Case DRIVE_REMOTE
                Types = "远程驱动器"
            Case DRIVE_CDROM
                Types = "光盘驱动器"
            Case DRIVE_RAMDISK
                Types = "随机存取磁盘"
            Case Else
                Types = "ERROR"
        End Select
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim DrivesN() As String
        Dim i As Short

        Call LoadDrivenames(DrivesN)
        For i = 0 To DriveCount() - 1
            ListBox1.Items.Add(DrivesN(i) & Types(DrivesN(i)))
        Next i
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -