imagelistexample.vb

来自「Samples are organized by chapter, and th」· VB 代码 · 共 111 行

VB
111
字号
Imports System.IO

Public Class ImageListExample
    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 cmdFillImageList As System.Windows.Forms.Button
    Friend WithEvents cmdDrawImageList As System.Windows.Forms.Button

    '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.cmdDrawImageList = New System.Windows.Forms.Button()
        Me.cmdFillImageList = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'cmdDrawImageList
        '
        Me.cmdDrawImageList.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cmdDrawImageList.Location = New System.Drawing.Point(176, 164)
        Me.cmdDrawImageList.Name = "cmdDrawImageList"
        Me.cmdDrawImageList.Size = New System.Drawing.Size(96, 24)
        Me.cmdDrawImageList.TabIndex = 1
        Me.cmdDrawImageList.Text = "Draw Images"
        '
        'cmdFillImageList
        '
        Me.cmdFillImageList.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cmdFillImageList.Location = New System.Drawing.Point(40, 164)
        Me.cmdFillImageList.Name = "cmdFillImageList"
        Me.cmdFillImageList.Size = New System.Drawing.Size(104, 24)
        Me.cmdFillImageList.TabIndex = 0
        Me.cmdFillImageList.Text = "Fill ImageList"
        '
        'ImageListExample
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(320, 210)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdDrawImageList, Me.cmdFillImageList})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "ImageListExample"
        Me.Text = "ImageList Example"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private IconImages As New System.Windows.Forms.ImageList()


    Private Sub cmdDrawImageList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrawImageList.Click

        ' Get the graphics device context for the form.
        Dim g As Graphics = Me.CreateGraphics
        Dim i As Integer

        ' Draw each image using the ImageList.Draw() method.
        For i = 0 To IconImages.Images.Count - 1
            IconImages.Draw(g, 30 + i * 30, 30, i)
        Next

        ' Release the graphics device context.
        g.Dispose()

    End Sub

    Private Sub cmdFillImageList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFillImageList.Click

        ' Configure the ImageList.
        IconImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        IconImages.ImageSize = New System.Drawing.Size(16, 16)

        ' Get all the icon files in the current directory.
        Dim IconFile As String, IconFiles As String()
        IconFiles = Directory.GetFiles(Application.StartupPath, "*.ico")

        ' Create an Image object for each file and add it to the ImageList.
        ' You can also use an Image subclass (like Icon).
        For Each IconFile In IconFiles
            Dim NewIcon As New Icon(IconFile)
            IconImages.Images.Add(NewIcon)
        Next

    End Sub
End Class

⌨️ 快捷键说明

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