【问题标题】:Drop Down & Picture Box integration下拉和图片框集成
【发布时间】:2012-10-28 00:35:23
【问题描述】:

我有一个简单的表格,里面有一个下拉框,里面有一个名字列表 和上面的图片框。

当我选择图片名称时,我怎样才能做到这一点 那个人的头像自动出现在图片框中?

【问题讨论】:

  • 您在标签中放置了三种不同的 VB 方言。你真正感兴趣的是哪一个?请不要添加不相关的标签。
  • 无需道歉,但删除标签会很有用。
  • 我可以通过将图像的文件路径放在组合框中来使其工作,但是当您单击组合框来选择一个人时,它只会显示 C:\filename 等。任何帮助都会很棒
  • 您需要某种方式将文件与此人的姓名相关联。

标签: vb6


【解决方案1】:

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

例如:

'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

【讨论】:

  • 不客气 :) 如果它适合你,请接受它作为答案 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多