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

📄 form1.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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
    Friend WithEvents bttnIterateHTable As System.Windows.Forms.Button
    Friend WithEvents bttnEnumHTable As System.Windows.Forms.Button
    Friend WithEvents bttnIterateAList As System.Windows.Forms.Button
    Friend WithEvents bttnEnumAList As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.bttnEnumHTable = New System.Windows.Forms.Button()
        Me.bttnIterateHTable = New System.Windows.Forms.Button()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.bttnIterateAList = New System.Windows.Forms.Button()
        Me.bttnEnumAList = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'bttnEnumHTable
        '
        Me.bttnEnumHTable.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.bttnEnumHTable.Location = New System.Drawing.Point(40, 165)
        Me.bttnEnumHTable.Name = "bttnEnumHTable"
        Me.bttnEnumHTable.Size = New System.Drawing.Size(168, 32)
        Me.bttnEnumHTable.TabIndex = 1
        Me.bttnEnumHTable.Text = "Enumerate HashTable"
        '
        'bttnIterateHTable
        '
        Me.bttnIterateHTable.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.bttnIterateHTable.Location = New System.Drawing.Point(40, 128)
        Me.bttnIterateHTable.Name = "bttnIterateHTable"
        Me.bttnIterateHTable.Size = New System.Drawing.Size(168, 32)
        Me.bttnIterateHTable.TabIndex = 0
        Me.bttnIterateHTable.Text = "Iterate HashTable"
        '
        'ListBox1
        '
        Me.ListBox1.Font = New System.Drawing.Font("Verdana", 9!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ListBox1.ItemHeight = 14
        Me.ListBox1.Location = New System.Drawing.Point(8, 16)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(240, 102)
        Me.ListBox1.TabIndex = 4
        '
        'bttnIterateAList
        '
        Me.bttnIterateAList.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.bttnIterateAList.Location = New System.Drawing.Point(40, 202)
        Me.bttnIterateAList.Name = "bttnIterateAList"
        Me.bttnIterateAList.Size = New System.Drawing.Size(168, 32)
        Me.bttnIterateAList.TabIndex = 2
        Me.bttnIterateAList.Text = "Iterate ArrayList"
        '
        'bttnEnumAList
        '
        Me.bttnEnumAList.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.bttnEnumAList.Location = New System.Drawing.Point(40, 239)
        Me.bttnEnumAList.Name = "bttnEnumAList"
        Me.bttnEnumAList.Size = New System.Drawing.Size(168, 32)
        Me.bttnEnumAList.TabIndex = 3
        Me.bttnEnumAList.Text = "Enumerate ArrayList"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(256, 285)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.bttnEnumAList, Me.bttnIterateAList, Me.bttnEnumHTable, Me.bttnIterateHTable})
        Me.Name = "Form1"
        Me.Text = "Enumeration Demo"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub bttnEnumHTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnEnumHTable.Click
        Dim HTable As New Hashtable()
        ' The keys in this routine are numeric
        HTable.Add(1, "A1")
        HTable.Add(2, 34.2)
        HTable.Add(3, "A1")
        HTable.Add(0, New Rectangle(0, 0, 100, 200))
        EnumerateTable(HTable)
        HTable.Remove(3)
        EnumerateTable(HTable)
    End Sub

    Private Sub bttnIterateHTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnIterateHTable.Click
        Dim HTable As New Hashtable()
        ' The keys in this routine are numeric
        HTable.Add(1, "A1")
        HTable.Add(2, 34.2)
        HTable.Add(3, "A1")
        HTable.Add(0, New Rectangle(0, 0, 100, 200))
        IterateTable(HTable)
        HTable.Remove(3)
        IterateTable(HTable)
    End Sub

    Private Sub bttnEnumAList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnEnumAList.Click
        Dim AList As New ArrayList()
        AList.Add("A1")
        AList.Add(34.2)
        AList.Add("A1")
        AList.Add(New Rectangle(0, 0, 100, 200))
        EnumerateList(AList)
        AList.Remove("A1")
        EnumerateList(AList)
    End Sub

    Private Sub bttnIterateAList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnIterateAList.Click
        Dim AList As New ArrayList()
        AList.Add("A1")
        AList.Add(34.2)
        AList.Add("A1")
        AList.Add(New Rectangle(0, 0, 100, 200))
        IterateList(AList)
        AList.Remove("A1")
        IterateList(AList)
    End Sub

    Private Sub EnumerateList(ByVal list As ArrayList)
        Dim ListEnum As IEnumerator
        ListEnum = list.GetEnumerator
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Enumerating List...")
        While ListEnum.MoveNext()
            ListBox1.Items.Add(ListEnum.Current.ToString)
        End While
    End Sub

    Private Sub IterateList(ByVal list As ArrayList)
        Dim element As Object
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Iterating through List...")
        For Each element In list
            ListBox1.Items.Add(element.ToString)
        Next
    End Sub

    Private Sub EnumerateTable(ByVal table As Hashtable)
        Dim TableEnum As IDictionaryEnumerator
        TableEnum = table.GetEnumerator
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Enumerating List...")
        While TableEnum.MoveNext()
            ListBox1.Items.Add(TableEnum.Current.ToString)
        End While
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Enumerating List...")
        TableEnum.Reset()
        While TableEnum.MoveNext()
            ListBox1.Items.Add(TableEnum.Value.ToString)

        End While
    End Sub

    Private Sub IterateTable(ByVal table As Hashtable)
        Dim element As Object
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Iterating through List...")
        For Each element In table.Values
            ListBox1.Items.Add(element.ToString)
        Next
    End Sub

End Class

⌨️ 快捷键说明

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