2012-11-07 38 views
-6

我有一個簡單的表格,下拉框中有一個名稱列表 和上面的圖片框。下拉和圖片框集成

我該如何做到這一點當我選擇一個名字的人的圖片 自動出現在圖片框?

+2

你已經把三個不同的VB方言標籤。你實際上對哪一個感興趣?請不要添加不相關的標籤。 –

+0

對不起,我的歉意 – jack

+1

沒有道歉需要,但標籤刪除將是有用的。 – Steve

回答

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 
+0

謝謝你親切的先生。 – jack

+0

不客氣:)請接受它作爲答案,如果它適合你:) – Hrqls