当前位置: 源码素材网 » VB教程 » 详情页

VB中的ImageList操作举例

  •   时间:2019-04-13
  • 概述:ImageList

本代码演示VB中常用的ImageList图像列表的用法示例,演示了在图片框显示ListImages集合中索引为"Balloon"的图形、在窗体中显示放大的ListImages("Note")图形、将Balloon.bmp加载到ListImages集合、将Note.bmp加载到ListImages集合等操作:

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "ImageList操作"
   ClientHeight    =   2715
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4335
   LinkTopic       =   "Form1"
   ScaleHeight     =   2715
   ScaleWidth      =   4335
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command3 
      BackColor       =   &H8000000E&
      Caption         =   "提取图形"
      Height          =   495
      Left            =   2400
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   840
      Width           =   1095
   End
   Begin VB.PictureBox Picture2 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   495
      Left            =   1560
      ScaleHeight     =   465
      ScaleWidth      =   585
      TabIndex        =   3
      Top             =   1320
      Width           =   615
   End
   Begin VB.PictureBox Picture1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ForeColor       =   &H80000008&
      Height          =   495
      Left            =   1560
      ScaleHeight     =   465
      ScaleWidth      =   585
      TabIndex        =   2
      Top             =   120
      Width           =   615
   End
   Begin VB.CommandButton Command2 
      BackColor       =   &H80000009&
      Caption         =   "Draw方法"
      Height          =   495
      Left            =   2400
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   1440
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000009&
      Caption         =   "创建图标"
      Height          =   495
      Left            =   2400
      MaskColor       =   &H00FFFFFF&
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   2040
      Width           =   1095
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   120
      Top             =   120
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   16777215
      MaskColor       =   16777215
      _Version        =   393216
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'“创建图标”按钮
'由图象返回一个图标并作为鼠标的图标
    Dim Pic1 As Picture
    Set Pic1 = ImageList1.ListImages(1).ExtractIcon
    With Me
        .MouseIcon = Pic1
        .MousePointer = vbCustom
    End With
End Sub

Private Sub Command2_Click()
'“Draw方法”按钮
    Dim intX As Integer, intY As Integer
    intX = ImageList1.ImageWidth
    intY = Me.Font.Size * 2
    ScaleMode = vbPoints                    '以点为单位
'绘正常图形
    ImageList1.ListImages(1).Draw Me.hDC, intX * 5, intY, imlNormal
'绘透明图形
    ImageList1.MaskColor = &HC0C0C0         '以灰色为屏蔽色
    ImageList1.UseMaskColor = True          '使图象透明
    ImageList1.ListImages(1).Draw Me.hDC, intX * 6, intY, imlTransparent
'绘选定图形
    ImageList1.ListImages(1).Draw Me.hDC, intX * 7, intY, imlSelected
'绘焦点图形
    ImageList1.ListImages(1).Draw Me.hDC, intX * 8, intY, imlFocus
End Sub

Private Sub Command3_Click()
'“提取图形”按钮
'在图片框显示ListImages集合中索引为"Balloon"的图形
    Set Picture1.Picture = ImageList1.ListImages("Balloon").Picture
'在图片框显示ListImages集合中索引为"Note"的图形
    Set Picture2.Picture = ImageList1.ListImages("Note").Picture
'将ListImages集合中索引为"Balloon"的图形保存在F盘
    SavePicture ImageList1.ListImages("Balloon").Picture, "F:\Balloon.bmp"
'在窗体中显示放大的ListImages("Balloon")图形
    With ImageList1
        PaintPicture .ListImages("Balloon").Picture, 0, 0, _
        ScaleX(.ImageWidth, vbPixels) * 4, ScaleY(.ImageHeight, vbPixels) * 4
    End With
'在窗体中显示放大的ListImages("Note")图形
    With ImageList1
        PaintPicture .ListImages("Note").Picture, 0, 1400, _
        ScaleX(.ImageWidth, vbPixels) * 4, ScaleY(.ImageHeight, vbPixels) * 4
    End With
End Sub

Private Sub Form_Load()
    Dim LImage As ListImage
'将Balloon.bmp加载到ListImages集合
    Set LImage = ImageList1.ListImages.Add(, "Balloon", _
        LoadPicture(App.Path & "\Balloon.bmp"))
'将Note.bmp加载到ListImages集合
    Set LImage = ImageList1.ListImages.Add(, "Note", _
        LoadPicture(App.Path & "\Note.bmp"))
End Sub

    相关声明:

      若“VB中的ImageList操作举例”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。