-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 に答える