我将图片框创建为一个对象,一个容器包含所有对象。所以,我调用returnIcon方法,如果需要,它使用generateIcon。我在容器中有一个方法来搜索正确的对象,然后返回该对象的图标。表单创建容器。我在那里呼叫图标,然后将它们发送到用户控件,在那里显示它。我的问题是图片框只显示上次调用它。我知道每个对象都被正确找到了。在用户控件中,我使用了picturebox.name,每个都是正确的。正在发送该值,但图像未显示。为什么只显示最后一个图片框?
基础对象是基本的LeagueObject,它包含在需要时创建的图片框(取决于布尔iamset)。
容器基本上只是一个LeagueObjects的列表(它以JSON反序列化的方式设置)。
图片框旅行: 联盟(基础)对象>>容器>>表格>>加载到表单中的userControl(有十个用户控件添加到表单中)显示的唯一图片框是需要pictureBox的最后一个用户控件。
- base object
Protected Sub generateIcon()
If Not iamset Then
img.Width = 45
img.Height = 45
img.SizeMode = PictureBoxSizeMode.Zoom
img.BorderStyle = BorderStyle.None
Try
img.Image = System.Drawing.Image.FromFile(Path.Combine(Path.GetTempPath(), "lolIcons", type, image.full))
Catch ex As Exception
End Try
img.BackColor = Color.White
setIcon()
AddHandler img.Click, AddressOf onIconClick
iamset = True
End If
End Sub
Public Function returnIcon() As PictureBox
generateIcon()
Return img
End Function
- base object collection
Public Function returnImageById(ByVal strID As String) As PictureBox
For Each champ In league_container.data
If champ.Value.id.ToString = strID Then
Console.WriteLine("found " + champ.Value.name)
Return champ.Value.returnIcon()
End If
Next
Console.WriteLine("Failed to find " + strID)
Return New PictureBox
End Function
- form
Public Sub loadUC(ByVal player As LeagueCurrentGameParticipant, ByVal kills As Double, ByVal deaths As Double, ByVal assists As Double, ByVal largestKillingSpree As Double, ByVal largestMultiKill As Double, ByVal killingSprees As Double, ByVal doubleKills As Double, ByVal tripleKills As Double, ByVal quadraKills As Double, ByVal pentaKills As Double, ByVal unRealKills As Double)
Dim uc As New ucMatchSummoner
uc.loadUC(player, rgocm.returnImageById(player.championId.ToString), rgossm.returnImageById(player.spell1Id.ToString()), rgossm.returnImageById(player.spell2Id.ToString()), kills, deaths, assists, largestKillingSpree, largestMultiKill, killingSprees, doubleKills, tripleKills, quadraKills, pentaKills, unRealKills)
tblpMain.Controls.Add(uc)
End Sub
- user control (This one is actually longer but I truncated it since it served no purpose. I was sending it ByVal but attempted ByRef in case anything changed, which it did not.
Public Sub loadUC(ByRef lcgp As LeagueCurrentGameParticipant, ByVal champImage As PictureBox, ByRef spell1 As PictureBox, ByRef spell2 As PictureBox, ByVal kills As Double, ByVal deaths As Double, ByVal assists As Double, ByVal largestKillingSpree As Double, ByVal largestMultiKill As Double, ByVal killingSprees As Double, ByVal doubleKills As Double, ByVal tripleKills As Double, ByVal quadraKills As Double, ByVal pentaKills As Double, ByVal unRealKills As Double)
lp = lcgp
loadPlayerCurrentGameInformation()
pnlChampIcon.Controls.Add(champImage)
flpSpells.Controls.Add(spell1)
flpSpells.Controls.Add(spell2)
End class
答案 0 :(得分:0)
显然,图片框不能像字符串那样一遍又一遍地返回。所以,我可以多次快速创建图像。标志的主要原因是因为我每次都下载图像,现在我只是将一组图像保存在临时文件夹中并访问那里的图像,这样可以有效地工作。标志iAmSet会阻止多次创建图片框,所以我删除了标记,所有内容都按预期工作。