-6

我有一个简单的表格,其中有一个下拉框,里面有一个名称列表,上面还有一个图片框。

当我选择一个名字时,我怎样才能使那个人的图片自动出现在图片框中?

4

1 回答 1

0

使用包含名称和图片文件的用户定义类型,然后创建此类型的数组

例如 :

'1 form with :
'    1 listbox : name=List1
'    1 picturebox : name=Picture1
Option Explicit

Private Type PERSON
  strName As String
  strPicture As String
End Type

Private mperFriend(4) As PERSON

Private Sub Form_Load()
  Dim intIndex As Integer
  mperFriend(0).strName = "Bob"
  mperFriend(0).strPicture = "Bob.jpg"
  mperFriend(1).strName = "Jane"
  mperFriend(1).strPicture = "Jane.jpg"
  mperFriend(2).strName = "Fred"
  mperFriend(2).strPicture = "Fred.jpg"
  mperFriend(3).strName = "Iris"
  mperFriend(3).strPicture = "Iris.jpg"
  mperFriend(4).strName = "John"
  mperFriend(4).strPicture = "John.jpg"
  List1.Clear
  For intIndex = 0 To UBound(mperFriend)
    List1.AddItem mperFriend(intIndex).strName
  Next intIndex
End Sub

Private Sub List1_Click()
  Caption = mperFriend(List1.ListIndex).strPicture
  Picture1.Picture = LoadPicture(App.Path & "\" & mperFriend(List1.ListIndex).strPicture)
End Sub
于 2012-11-08T08:34:47.697 回答