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

📄 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 Button1 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.ListBox1 = New System.Windows.Forms.ListBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        '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, 48)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(480, 284)
        Me.ListBox1.TabIndex = 2
        '
        'Button1
        '
        Me.Button1.Font = New System.Drawing.Font("Verdana", 9!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(8, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(168, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Show Keys and Values"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(512, 373)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.Button1})
        Me.Name = "Form1"
        Me.Text = "SortedList Demo"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sList As New System.Collections.SortedList()

        ' USE THE COMMENTED LINES TO CREATE A SORTEDLIST WITH
        ' DATES AS KEYS AND NAMES AS VALUES
        'sList.Add(#4/5/1990#, "Andrea")
        'sList.Add(#1/12/1989#, "Joe")
        'sList.Add(#12/22/2000#, "Albert")
        'sList.Add(#8/8/1965#, "Elisabeth")
        'sList.Add(#11/11/1971#, "Robert")
        'sList.Add(#3/9/1998#, "Mary Ann")
        'sList.Add(#9/20/1999#, "Alice")
        'sList.Add(#4/9/2004#, "Nicole")
        'sList.Add(#10/2/2001#, "Bruce")
        'sList.Add(#5/25/1985#, "Andrea")

        sList.Add(16, "item 3")
        sList.Add(10, "item 9")
        sList.Add(15, "item 4")
        sList.Add(17, "item 2")
        sList.Add(11, "item 8")
        sList.Add(14, "item 5")
        sList.Add(18, "item 1")
        sList.Add(12, "item 7")
        sList.Add(19, "item 0")
        sList.Add(13, "item 6")

        Dim SLEnum As IDictionaryEnumerator
        SLEnum = sList.GetEnumerator()
        ListBox1.Items.Clear()

        ListBox1.Items.Add("The HashTable's Keys and Value")
        While SLEnum.MoveNext
            ListBox1.Items.Add("Key = " & SLEnum.Key.ToString & ", Value= " & SLEnum.Value.ToString)
        End While

        ListBox1.Items.Add("The HashTable's Values by Index")
        Dim idx As Integer
        For idx = 0 To sList.Count - 1
            ListBox1.Items.Add("Item " & sList.GetByIndex(idx).ToString & " is at location " & sList.IndexOfValue(sList.GetByIndex(idx)).ToString)
        Next

        ListBox1.Items.Add("The HashTable's Keys by Index")
        For idx = 0 To sList.Count - 1
            ListBox1.Items.Add("The key at location " & idx.ToString & " is " & sList.GetKey(idx).ToString)
        Next
    End Sub

End Class

⌨️ 快捷键说明

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